From: gabriele renzi Date: 2004-06-29T04:13:24+09:00 Subject: Re: (oddity) applying objects with #call() implicitly il Mon, 28 Jun 2004 19:41:54 +0200, Florian Gross ha scritto:: >gabriele renzi wrote: >> "p" may stand for self#p, or a local variable named "p". > >This case can be resolved fairly easily. (If there's an assignment to p >then it is a variable) Yes, and if there is a variable named "foo" in foo arg1 then it is calling that one instead of the old 'foo' method. >However think about this case: > >def foo > puts 0 > lambda { puts 1; lambda { puts 2; lambda { puts 3 }}} >end > >foo # What will this do? 0 #=> # >foo() # What will this do? 0 #=> # >x = foo; x # What will this do? 0 #=> # >x = foo; x() # What will this do? 01 #=> # >x = foo(); x # What will this do? 0 #=> # >x = foo(); x() # What will this do? 01 #=> # >x = foo; y = x; y # What will this do? 0 #=> # >x = foo(); y = x; y # What will this do? 0 #=> # >x = foo(); y = x(); y # What will this do? 01 #=> # >x = foo; y = x(); y # What will this do? 01 #=> # >x = foo; y = x(); y() # What will this do? 012 #=> # >x = foo; y = x; y() # What will this do? 01 #=> # >x = foo(); y = x(); y # What will this do? 01 #=> # >x = foo(); y = x(); y() # What will this do? 012 #=> # >Etc. -- there are many cases here. yes, but the rule is quite simple :) Note that I may have 'computed' the things myself and I may be wrong. Anyway, sample implementation: >> B=binding => # >> def method_missing(s,*a,&b) >> eval(s.to_s,B).call *a, &b >> end => nil >> def foo >> puts 0 >> lambda { puts 1; lambda { puts 2; lambda { puts 3 }}} >> end => nil >> foo 0 => # >> foo() 0 => # >> x=foo(); x => # >> x=foo(); x() 0 1 => # >> x=foo; x() 0 1 => # >> x=foo; y=x; y 0 => # >> x=foo; y=x(); y 0 1 => # >> x=foo; y=x(); y() 0 1 2 => # >> x=foo(); y=x(); y() 0 1 2 => # >> >I think the problem is that you can't have optional ()-arguments and () >as a call operator as the same time. this is what I usually thought. After reading the msg [see first msg] I changed slightly my mind. >However we need optional () because of things like this: yes, totally agree.