From: Sean O'Halpin Date: 2005-10-20T05:33:37+09:00 Subject: Re: Method annotation and anonymous functions On 10/19/05, Paul Brannan wrote: > I like this too. And there's no reason IMO why we can't have both > anonymous functions and anonymous closures (so def and lambda could have > the same syntax but lambda would create a closure, while def would not). I agree. See the thread "Anonymous methods, blocks etc. (Cont. 'default block params')" starting at ruby-talk/160709 for some recent discussion about this. > > Then we could also have named closures as well: > > class Foo > a = 42 > lambda foo(b, c) > puts a, b, c > end > end That's an interesting idea. It would certainly be orthogonal. However, you can already do that with define_method: class Foo a = 42 define_method(:foo) do |b, c| puts a, b, c end end Foo.new.foo(1,2) __END__ 42 1 2 > The only problem I have with this is that currently lambda is not a > keyword; it is a method that takes a block and returns a Proc object. > Creating new keywords, especially out of existing non-keywords, should > always be done with caution. Agreed. > Currently, the following code works fine: [snip] > But I would imagine that if lambda were a keyword this would confuse the > parser. Well, I doubt it would break ~much~ code. It would be quite an unusual thing to define a function named lamdba(), no? [snip discussion about || vs <> block local syntax] I think you're on a losing wicket here. It seems that the zeitgeist is with the semi-colon to introduce block locals. Regards, Sean