From: Brian Candler Date: 2003-03-24T18:56:22+09:00 Subject: Re: Ruby lecture slides (was Strong advantages over Python) On Mon, Mar 24, 2003 at 11:40:52AM +0900, Paul Prescod wrote: > Brian Candler wrote: > >... > > > > You can write that almost exactly the same in Ruby of course: substitute > > proc { |foo| ... } for lambda foo: > > Right, you've wrapped the block in a function. Well, a Proc object to be precise... the nearest equivalent Ruby has to a 'function' is a Method, and that's not quite the same thing. > It strikes me as a minor > wart (of the same sort that all languages have) that if you want to pass > a single closure you use block syntax but if you want to pass multiple > you switch to procs. I guess that keeps the syntax simpler. I think it's just for clarity and ease of use. I consider the passing of a single block as syntactic sugar, because you can treat it as an explicit Proc object if you so wish: def myfunc(&block) &block.call # same as 'yield' end It's just that so often all you want to do is pass a single block, and the language syntax has been designed to handle that case in a particularly easy-to-use way. It's much nicer to write 3.times do |x| puts x end than 3.times(lambda do |x| puts x end) Regards, Brian.