On Thu, May 29, 2008 at 9:19 PM, Nobuyoshi Nakada <nobu / ruby-lang.org> wrote: > Hi, > > At Thu, 29 May 2008 22:54:24 +0900, > Paul Brannan wrote in [ruby-core:16991]: >> > [1] Of course, this has been my unfortunate experience of trying to >> > explain what lambda is to newcomers from C++: their eyes >> > glazed-over, thinking that it was mathematics (groan!) I guess. >> >> C++ is getting lambdas in the future: >> >> [&] (int arg1, Foo const & arg2) { return arg2.foo(arg1); } >> >> I'm surprised nobody's suggested that [&] be added as an alias for -> >> (please don't suggest it). > > How do you read this: > foobar &(foo) {foo.bar()}, > > foobar(&foo.to_proc) {foo.bar()} > or > foobar(lambda{|foo|foo.bar()}) > ? > > The former causes syntax error, but it would introduce > confusion. In this C++0x syntax, the [] surrounds the local variables that the lambda should have access to (making it a closure). Variables can be specified by reference or by value/copy. A plain "&" allows reference access to all variables in scope - just like Ruby. As Paul said, nobody should suggest this for Ruby. This complexity isn't appropriate or needed. The Ruby VM/compiler can make optimizations based on what variables the block uses. http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions