From: Mark Probert Date: 2002-12-06T12:17:50+09:00 Subject: Re: [ANN] ratlast 0.1 -- embedded FORTH in Ruby Hi, Joel. Joel VanderWerf wrote: >>>> >>>>t.eval(": linear ( a b -- ) create swap , , does> dup >r @ * r> 4 + @ >>>>+ ;") t.eval("3 17 linear aline") >>> > > But closures can do something quite different--they can share a variable > binding with the enclosing scope: > > a = 1 > b = 2 > > linear = proc { proc {|x|a*x+b} } > This is also (almost) true of the Forth code. Here, the binding happens at the line 3 17 linear aline I could have written this code: i = j = 1 until i <= 10 t.eval("#{i} #{j} linear aline_#{i}") # rename the fn to avoid conflict x = rand(100) t.eval("#{x} aline_#{i}") puts "x=#{x} : #{i}x + #{j} = #{t.caputure[0]}" i += 1 j += 5 t.clear end I think this is the same as closures, or have I misunderstood? Regards, -mark.