Dne čtvrtek 26. května 2016 18:03:50 UTC+2 Yichao Yu napsal(a): > > > Because it is done at compile time, where you can even decide to call > > completely different function. See > > dequeue = ..... > > dequeue[:first] # is replaced with different function than dequeue[1] > > dequeue[:last] # is replaced with different function than dequeue[end] ( > > O(1) vs O(n) ) > > I don't see what you mean by compile time. You cannot dispatch on the > symbol at compile time. If you use syntax level rewrite, there's no > point of using symbol either. > What do you mean by syntax level. Why there is no point for using symbol if that's the case?
> > > > > Because you can define your own syntax. The :middle was just stupid > example > > to show you, that you can decide on your own symbol based on collection > you > > are working with ( say there is collection which when accessing middle > has > > different complexity than accessing other elements). > > You can easily do this by defining your own token. Misusing the symbol > syntax isn't the right way to go. > Yeah, I also feel that using symbol is not the right approach, but I couldn't think about any other simpler way of doing that. Can you show me what do you mean by token? > > > > > Of course you can do arithmetics with this approach. > > No you can't. Not in a way that you can overload it for different types > anyway. > > >> Which is what make the way you propose unsatisfying. > >> > > > > Are you talking about [ FIRST = :first ]? > > If so, I could argue about this since you can't also do [ LAST = end ] > > The only difference is that [ LAST = end ] throws error at compile time. > > The difference is that `end` is a keyword. And symbol literal is not. > Which is intended and its fine. The problem is that user won't know, what symbols should he use, unless he checks the docs, which is not nice.
