From: Gary Wright Date: 2007-07-11T03:28:59+09:00 Subject: Re: Syntax sugar: method[](...) => method(...) On Jul 9, 2007, at 11:54 PM, Yukihiro Matsumoto wrote: > In message "Re: Syntax sugar: method[](...) => method(...)" > on Tue, 10 Jul 2007 04:08:26 +0900, Gary Wright > writes: > > |This would probably be a headache from a parsing perspective but what > |about something like: > | > | obj.login@[date] > > Why we need syntax sugar when we can just call > > obj.login(date) I think that there is a significant semantic difference (to the programmer) between brackets and parenthesis. foo(bar) # foo is interpreted as a verb foo[bar] # foo is interpreted as a noun (a collection of some sort) The language rules also force different semantics on those two expressions. In the first, 'foo' must be a method associated with self and so the method has semantics defined by the definition of 'foo' but it isn't clear from the syntax that some sort of indexing is being attempted. In the second expression, there may be one or two method calls depending on whether 'foo' is a local variable or not. In either case, the interpretation of [bar] is not done by a method associated with self but instead by a method associated with the value of 'foo', which might be the result of a method call. The benefit of some alternate indexing syntax is that the name of the collection and the implementation of indexing on the collection can be localized to a single method associated with self rather than delegating the indexing logic to an intermediate object (the value of 'foo'). This would also probably reek havoc on parse.y but what about: foo@(bar) foo@(bar) = x This builds upon Ruby's use of foo! and foo? as having distinct meanings. Gary Wright