From: William James Date: 2009-01-12T09:14:23+09:00 Subject: Re: functional programming Pascal J. Bourguignon wrote: > There's a difference between (def smallest(x) ; x ; end) > and (smallest = (lambda { |x| x })) > > In the former case, you can write (smallest [1,2,3]) > in the later you can't: > > > irb(main):001:0> (def smallest(x) ; x ; end) > (def smallest(x) ; x ; end) > nil > irb(main):002:0> (smallest [1,2,3]) > (smallest [1,2,3]) > [1, 2, 3] > irb(main):003:0> (smallest = (lambda { |x| x })) > (smallest = (lambda { |x| x })) > # > irb(main):004:0> (smallest [1,2,3]) > (smallest [1,2,3]) > (irb):3: warning: multiple values for a block parameter (3 for 1) > from (irb):4 > [1, 2, 3] foo = proc{|x| "#{x.size} items: #{ x.join ' & ' }" } ==># foo.call( [2,3,4] ) ==>"3 items: 2 & 3 & 4" foo[ [2,3,4] ] ==>"3 items: 2 & 3 & 4"