From: Magnus Holm Date: 2010-09-15T14:41:24+09:00 Subject: [ruby-core:32392] Re: Making custom_lambda() work Technically, it's possible. The parser keeps a list of the local variables in the scope, so when it encounters "x()" it can simply check: if local_variables.include?("x") ? "x.call()" : "x()". But as matz mentioned, this isn't the easiest thing to do in the current parser. I'm not sure if this special syntax is a good or bad thing, but I just thought I mention one way this could be accomplished. // Magnus Holm On Wed, Sep 15, 2010 at 05:41, Gary Wright wrote: > > On Sep 14, 2010, at 12:11 PM, Magnus Holm wrote: > >> Of course, if you read the proposal again, you'll see that it doesn't >> even mention the word "lambda". I'm talking about changing the meaning >> of "foo()" where foo is a local variable. So in this example: >> >> a = [1,2,3] >> s = "Hello World!" >> h = { :color => :red } >> >> a() >> s() >> h() >> >> That would actually run "a.call()", "s.call()" and "h.call()". There's >> no special case for lambda. > > I think you are still stuck with an ambiguity that can't be resolved > at parse time. The problem is that 'x()' already has a meaning to the > parser when x is a local variable. You can't re-write this to > x.call() at parse time because that would bypass the method call to 'x'. > The best you could do would be to restart the call as x.call() when 'x' > isn't found. > > I'm still against it because of the special casing, and the complexity > of interacting with method_missing: > > �� �� �� ��search for method 'x' and invoke if found > �� �� �� ��search for method 'x.call' and invoke if found > �� �� �� ��search for method_missing and invoke if found > �� �� �� ��search for 'x.method_missing' and invoke if found > > I'm not even sure if that would be the 'correct' order for handling > method_missing. > > I just don't see why #call should have special syntax especially when > you can already get pretty darn close with #[]: > > �� �� �� ��some_proc_like_reference[1,2,3] > > Gary Wright > > > > > >