Lexical scope and closures

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 :slight_smile:

in either case, a, b are local, c is method-wise variable.

my old codes wouldn’t break w this change… but I’m just a nuby yet and I
program like c/pascal :wink:

  					matz.

kind regards
-botp

“Peña, Botp” botp@delmonte-phil.com schrieb im Newsbeitrag
news:20030214161242.56653781C4@proxy-dmz.delmonte-phil.com

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 :slight_smile:

I remindes me more of the lisp ‘let’ - and I think this was intended. :slight_smile:

robert

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(2i, i**2) { |a, b|
# a is initialized to 2
i
# b is initialized to i**2
}
}

···

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 :slight_smile:

I remindes me more of the lisp ‘let’ - and I think this was intended. :slight_smile:


– 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)