From: "David A. Black" Date: 2008-05-22T18:55:23+09:00 Subject: Re: lambda, ->, haskell, and so on Hi -- On Thu, 22 May 2008, Nate_Wiger@playstation.sony.com wrote: > Hi- > > Yukihiro Matsumoto wrote on 05/19/2008 10:23:29 AM: >> Hi, >> >> In message "Re: lambda, ->, haskell, and so on" >> on Tue, 20 May 2008 01:49:04 +0900, Nate_Wiger@playstation.sony. >> com writes: >> >> |Second, there are a couple alternatives that we could use, leveraging >> |existing Ruby syntax: >> | >> | http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/16662 >> | http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/16616 >> >> So, you prefer lambda(x) {...} or x => {...} over ->(x){...}, right? >> The latter (=>) conflicts with other part of Ruby syntax, namely hash >> literals, besides it complicates the language. >> >> I am not fond of "lambda" being keyword, because >> >> * it changes meaning of the valid syntax ("lambda(a){p a}" is valid >> in 1.8 with different semantics). >> * it's long (6 letters). considering the functional programming >> trend in Ruby and other languages, we will see anonymous function >> expression more often in the future. > > There is also Ara's suggestion of using "def" for this purpose: > > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/16804 I think it was originally Dave Thomas's idea (at RubyConf 2005). I'm also in favor of it, but see Matz's comments earlier in the thread about concerns over the connotations of "def[ine]" with regard to anonymity. > This would make Ruby more consistent with other languages: > > Ruby > def name; "stuff"; end > name = def() "stuff"; end > > Perl 5 > sub name { "stuff"; } > $name = sub { "stuff"; } > > JavaScript > function name(){ "stuff"; } > name = function(){ "stuff"; } I wouldn't worry about that as a goal in itself (I love Ruby largely for the ways in which it is *not* consistent with other languages :-) but it's interesting to be reminded of these. Again, see Matz's comments about "def". David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!