From: k Date: 2002-05-28T18:41:40+09:00 Subject: Re: confused about scope of block parameter I wrote: > It outputs "OuterOuter". I expected "InnerOuter". Oops. I typed badly. It does in fact output "InnerInner". But the question still remains. "k" wrote in message news:ZQHI8.123742$UV4.223942@rwcrnsc54... > I'm not certain how to word this question precisely. So I'll begin with an > example. > Consider this bit of Ruby: > > foo = "Outer" > (lambda {|foo| print foo}).call("Inner") > print foo > > It outputs "OuterOuter". I expected "InnerOuter". I thought that this would > be equivalent to the following bit of Lisp, which does output "InnerOuter": > > (let ((foo "Outer")) > (funcall (lambda (foo) (format t foo)) "Inner") > (format t foo)) > > Can someone explain the Ruby behavior here? Is the block parameter foo > really bound to the containing scope's foo variable? Or am I missing > something very basic? Why would it work this way instead of creating a new > foo in the block's new scope? > > Thanks! > k > >