On Mon, Dec 29, 2003 at 02:34:40PM +0900, Nathaniel Talbott wrote: > On Dec 28, 2003, at 23:11, Martin DeMello wrote: > > >Nathaniel Talbott <nathaniel / talbott.ws> wrote: > >>Isn't it this behavior that makes it possible to define a recursive > >>block? > >> > >> y = 0 > >> x = proc{y += 1; x.call unless(y == 100); y} > >> p x.call > >> > >>I suppose you could require a prior assignment to x in this case, but > >>that starts to smell like having to declare variables... > > > >This is not a proper recursive block - for instance > > > >y = 0 > >x = proc{y += 1; x.call unless(y == 100); y} > >z = x > >x = nil > >z.call > > "Not proper" might be strong language, but yes, it could definitely be > broken. Do you have a better construct for a recursive block? >> y = 0; z = proc{ x = proc{ y+= 1; x.call unless y == 100 }; x.call } => #<Proc:0x401af0f0@(irb):3> >> z.call => nil >> y => 100 With the new block local rules, y = 0; z = proc{|*z| z = proc{y += 1; z.call unless y == 100}; z.call } a = z z = nil a.call would work too (you'd get a warning IIRC, though). If you're "evil" enough you might like the following too: y = 0 proc {|l| proc{|f| f.call(f)}.call(proc{|f| l.call(proc{|*x| f.call(f).call(x)})}) }.call(proc {|r| proc{y += 1; r.call unless y == 100}}).call ;) -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com I tried the clone syscall on me, but it didn't work. -- Mike Neuffer trying to fix a serious time problem