From: Jim Weirich Date: 2003-02-15T08:50:31+09:00 Subject: Re: Lexical scope and closures On Fri, 2003-02-14 at 05:11, Robert Klemme wrote: > > Matz [mailto:matz@ruby-lang.org] wrote kindly: > > > > > arr.each {|i| > > > let a = .. > > > let b = .. > > > c = .. > > > ... > > > } > > > > I like this, reminds me of basic. Or maybe ":=" wc reminds me of > > pascal :-) > > I remindes me more of the lisp 'let' - and I think this was intended. :-) Actually, to me, it is the "local" command that reminds me of the Lisp-ish let (despite the names). In Lisp (IIRC) "let" is a macro that expands into a lambda form with the variables as formal arguments in the lambda. This is exactly what the "local" method is doing. In fact, I recall the Lisp "let" macro allows initial values to be specified as well. To make the analogy complete, we could do ... arr.each {|i| local(2*i, i**2) { |a, b| # a is initialized to 2*i # b is initialized to i**2 } } -- -- 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)