From: "Suraj N. Kurapati" Date: 2008-05-28T12:24:49+09:00 Subject: Re: [PATCH] lambda with normal block syntax David Flanagan wrote: > Well of course--its Matz's language. But let's engage the debate with > reasonable expectations. And I'm just trying to point out that given > the stage of the 1.9 release, it is probably unreasonable to expect an > alternative to -> in 1.9. The most that can reasonably be hoped for, in > my opinion, is the removal of the -> syntax. Why is the addition of bare blocks considered so daunting? Unlike the removal of ->, the addition of bare blocks is *fully* backwards compatible with both Ruby 1.8.x and 1.9.0-x! For instance, whereas early adopters of 1.9.0-x need to change their code after -> removal, nobody needs to change their code after the addition of bare blocks. I would *really* like the addition of bare blocks to be considered for Ruby 1.9. This addition finally makes "functional programming" invisible to the user by making blocks into first-class citizens (literals) in Ruby syntax. Just think of the developer mind-share this would capture, as Ruby's functional programming capabilities can be *explained* much more easily to a newcomer (without scaring them away[1] with "lambda"): Ruby has *code blocks* -- which are blocks of code that you can pass around and execute whenever and wherever you want. This kind of explanation is reinforced by the fact that users *see* blocks being used _everywhere_: iterators, thread bodies, etc. Furthermore, what follows the POLS more than being able to *snatch* a block (yes, with your bare hands) and place it (and reuse it) anywhere in your code: a = [1, 2, 3] b = [4, 5, 6] # here's a traditional code block a.each {|x| puts 2 * x } # why can't I snatch it and reuse it? code_block = {|x| puts 2 * x } a.each &code_block # if code blocks are really literal functions... doubler = {|x| 2 * x } # *snatch* printer = {|x| puts x } # *snatch* a.each(printer(doubler)) # place This kind of classic function composition, is made so simple and intuitive with bare blocks: they are a fundamental and highly idiomatic building block in the Ruby language today. To testify, I've been playing with bare blocks for the past two days and I find them to be an absolute treat to use, especially in the do..end form because the "do" gives a strong clue the code block is a function: # an "adder" *do*es something with x and y: # it adds x and y and returns the sum adder = do |x, y| x + y end # call the "adder" and ask it to *do* something with 1 and 2. # but what does the "adder" do? see above adder.call(1, 2) #=> 3 Thanks for your consideration. [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.