From: Jim Weirich Date: 2002-08-22T13:00:13+09:00 Subject: Re: blocks and lambdas, or blocks as first-class entities >>>>> "Rafael" == Rafael Sevilla writes: Rafael> [...] What if we made a block a first class entity, Rafael> allowing one to assign a block to a variable, and pass a Rafael> block as a formal parameter to a method? This of course Rafael> would also mean making a block an object, which in my Rafael> opinion is a very powerful idea. A Proc object is an objectified block. You can create a proc object by saying ... proc { |args| ... } or lambda { |args| ... } or Proc.new { |args| ... } Proc objects can be assigned to variables and passed to functions Rafael> So you might have some code that looks like this: Rafael> def foo(b1, b2) Rafael> b1.execute(a, b, c) Rafael> b2.execute(d, e) Rafael> end Rafael> tmp_blk = { |a, b| ... } Rafael> foo({ |a, b, c| ... }, tmp_blk) Rafael> {|a| ... }.execute(b) Or using procs ... def foo(b1, b2) b1.call(a, b, c) b2.call(d, e) end tmp_blk = proc { |a, b| ...} foo(proc { |a, b, c| ... }, tmp_blk) proc { |a| ...}.call(b) Very similar to your proposal, except we add "proc" and use "call" rather than "execute" to invoke the proc. -- -- Jim Weirich jweirich@one.net http://w3.one.net/~jweirich --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)