Re:Ruby is not a callable orientated language
by viraptor on Sunday February 21, 2010 @11:26AM
(#1140723)
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
Re:Ruby is not a callable orientated language
by wycats on Sunday February 21, 2010 @03:21PM
(#1141175)
foo()() doesn't seem better than foo.call
To "fix" this you'd have to require parens when calling all functions, since you have no way of knowing whether the function returns a block or not. The other option is only allowing parens to call blocks at certain times and not at others - certainly confusing!