[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Redefining locals
- From: Matt Hellige <matt@...>
- Date: Thu, 11 Nov 2004 15:22:04 -0600
(Trying to get back to the topic...)
Again deferring to Scheme, redefinitions act the same as
assignments... So, for example:
guile> (define x 3)
guile> (define (f) x)
guile> (f)
3
guile> (define x 5)
guile> (f)
5
guile>
Here's R5RS again:
At the top level of a program, a definition
(define <variable> <expression>)
has essentially the same effect as the assignment expression
(set! <variable> <expression>)
if <variable> is bound. If <variable> is not bound, however, then
the definition will bind <variable> to a new location before
performing the assignment, whereas it would be an error to perform a
set! on an unbound variable.
I think it would be nice for lua to adopt a similar policy for locals,
as has been suggested by others. I'd like:
local x = 3
function f() print(x) end
f()
local x = 5
f()
to print '3, 5' instead of '3, 3'... It seems like this still allows
the:
local _, _ = f()
idiom to work as expected.
Matt
--
Matt Hellige matt@immute.net