From: matz@... (Yukihiro Matsumoto) Date: 2004-03-04T09:59:53+09:00 Subject: Re: concerns about Proc,lambda,block Hi, In message "Re: concerns about Proc,lambda,block" on 04/03/04, Dave Thomas writes: |On Mar 3, 2004, at 17:02, Yukihiro Matsumoto wrote: |> |Matz: have you had a chance to read these pages? Are they technically |> |accurate? |> |> No. Where can I read your "writeup"? | |http://www.pragmaticprogrammer.com/extracts/blocks.pdf I checked. Some of your description is based on bugs I fixed already. For example, def meth1(&block) block.call end res = meth1 do break 99 end This code does not raise exception any longer. There are no such things like iterator context and closure context in Procs. There are several basic rules: * a Proc is a wrapper for a block attached to the method. * break and return cause LocalJumpError when a proc is executed (by Proc#call) after passing attached method invocation. We call it orphan proc, but you may name it a better name. * a Proc from "lambda" catches LocalJumpError caused by break and return from within its body, then terminates the execution gracefully. * use of "Kernel#proc" is no longer encouraged; use "lambda" instead. In the above example, block is called within "meth1" which the block is attached to, so that block is not orphan, no exception; whereas def meth2(&block) block end b = meth2{break 99} res = b.call should cause LocalJumpError, because a Proc is called after the execution of meth2. matz.