From: stevetuckner Date: 2005-10-20T04:45:32+09:00 Subject: Re: Method annotation and anonymous functions David A. Black wrote: > Hi -- > > On Thu, 20 Oct 2005, stevetuckner wrote: > >> I want to start a discussion about two things that Matz talked about >> at the rubycon. Dave Thomas suggested that we could get Matz' >> anonymous function by using "def" without a name. Others suggested >> that if def returned a method object, then annotations could be >> applied to that object. So here goes my suggestions. As they stand, >> they are not even parseable by Ruby, but lets start talking about it >> anyway. >> >> Anonymous functions: >> >> x = def (a=1,b=2) { ... } >> y = def(a,b=3) begin >> ..... >> end > > > I don't think either of those is exactly what Dave suggested: > > x = def (a=1,b=2) > ... > end What I don't like about this is that to do one liners, you need to do: x = def(a=1, b=2); ...; end > > without the braces, and without 'begin', just like a method > definition. > > I actually like the second iteration of the idea more: > > x = lambda (a=1,b=2) > ... > end same issue > > using method-definition style for an anonymous function, but a > different keyword. This keeps it more robust; there's a more "solid" > indication that it's something other than a def. I don't mind lambda over def. What object would lambda return? A proc object? Could annotations be applied to it? > > (Actually that was sort of the third iteration :-) The first was: > > -> (a=1,b=2) > ... > end > > which I posted here last week in an attempt to at least ameliorate the > arrow thing. But having a real keyword plus the no-braces is > definitely better.) > > > > David >