Lets change compiler so it replace 
array[i]

with 
@getindex(array, i)

instead of 
getindex(array, i)

What we gain:

array[end]

:end can be converted to length(array) in julia itself which is nice!

collections (dict, set, queue...)

dequeue = ... # its a linked list
dequeue[first]
dequeue[last]  # IMO :last causes less confusion than :end for new 
programmers, but it doesn't really matter
dequeue[3]


macro getindex(q:Queue, key)
  key == :first && return :(peekfirst(q))  # complexity O(1)
  key == :last  && return :(peeklast(q))   # complexity O(1)
  isa(key, Int) && return :(peek(q, key))  # complexity O(n)
end


let's say that we would also have special syntax for 

*popindex()* 
array[index]--  #completely made up

*and insertindex()*
array[index]++

Then we could do the similar thing as above
macro popindex(q:Queue, key)
  key == :first && return :(shift!(q))
  key == :last  && return :(polll!(q))
  isa(key, Int) && return :(deleteat!(q, key))
end
macro insertindex .....


This looks pretty nice, don't you think?

We could even some crazy stuff like this:
type  Foo
 a; b; c; d
end

macro setindex(f::Foo, key, value)
  return :(setfield(f, key, value))
end

f = Foo(1, 2, 3, 4)
f[c] = 10
Seems like we don't need the dot accessing aka *foo.var* huh?

Reply via email to