4 ms·
I'm not sure why people say that. It seems obvious. What optional '()' needs to achieve is: def a 42 end a => 42 a() => 42 So the gramm
by viraptor 17y ago
I'm not sure why people say that. It seems obvious. What optional '()' needs to achieve is:
def a
42
end
a => 42
a() => 42
So the grammar could use something like:
call = expression '(' ... ')'
call_or_variable = expression
it cannot be reversed really, because then it would match `call_or_variable` '(' ')' - which would make `a()` fail to run, because 42 is not callable (or you'd have to use backtracking and guessing... evil).
It cannot be the case of "no way of knowing", because at parsing time in dynamic language you don't know what the result of a function is - you only look at grammar. So in the simplest possible way, if the '()' is optional, then... I'm not sure how to call it, but let's say - '()' binds stronger than 'possible application':
foo => call foo
foo() => call foo
foo()() => call proc
- wycats 17y agofoo()() doesn't seem better than foo.call