[grammarians] ambiguity with method call?
Sean O'Halpin
sean.ohalpin at gmail.com
Tue Nov 29 16:23:08 EST 2005
On 11/29/05, Terence Parr <parrt at cs.usfca.edu> wrote:
> Howdy,
>
> What does
>
> foo [1]
>
> parse as? foo could be a variable and then foo is a simple array var:
>
> foo = [a,b]
> foo[1]
>
> If foo is a method, it could return an array and then you could
> access the 1st element:
>
> def foo
> return [a,b]
> end
> foo[1]
>
> It could also be a method with args:
>
> def foo x
> ...
> end
> foo [1] # same as foo([1])
>
> This 5x ways to do anything syntax is truly a burden for the
> implementor (and as a user one of the reasons I hated perl).
> Regardless, is this a true *syntactic* ambiguity as I suspect? I.e.,
> you need to simply pick an interpretation by dictum in the manual?
>
> Thanks,
> Ter
It gets worse ;)
There is also the case where [] can be a synonym for Proc#call, e.g.
foo = proc {|x| x*x }
foo [2] #=> 4
Regards,
Sean
More information about the Rubygrammar-grammarians
mailing list