[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Closure of lexical environment in Scheme closures
- From: Brian Casiello <bcasiello@...>
- Date: Thu, 11 Nov 2004 16:33:28 -0500
On Thu, 11 Nov 2004 21:23:31 +0000, Dr. Rich Artym
> On Thu, Nov 11, 2004 at 03:54:36PM -0500, Aaron Brown wrote:
> > I posted a Scheme program and an equivalent Lua program
> > earlier. Here are improved versions. (As I said, I'm not
> > fluent in Scheme, so they might not be exactly equivalent,
> > but they're close enough for our purposes.)
> > ;; Scheme version:
> > (define func nil)
> > (let ((foo 'bar))
> > (set! func (lambda ()
> > foo))
> > (set! foo 'baz)) ;; Alters the foo within func.
> > ;; Outside the 'let':
> > (define foo 'quux) ;; If this were a 'set!', we'd get an
> > ;; error.
> > (func) ;; Returns baz.
> Guile is not valid Scheme, since Scheme made the set! syntactic keyword
> illegal because it broke closure encapsulation. This is *precisely*
> the issue --- if Scheme is our reference on this particular issue then
> we're illegally modifying our Lua closures.
> I gave some history on this in the old (slightly hijacked) thread, so
> I'll repeat it here where it's more relevant:
> || Admittedly it used to be legal in older versions of Scheme (up to 5c4),
> || and then Scheme r4rs referred to it as a "compatible extension but not
> || a compliant implementation" of Scheme (lol, Scheme had a lot of politics
> || in those days). And finally they bit the bullet and simply made it
> || illegal Scheme starting from r5rs. Scheme's always tried to move in
> || the direction of lambda calculus purity.
> || The Guile folks chose to be non-compliant on this point because they
> || needed the functionality of such a construct, which is fair enough.
> Although Scheme makes a good reference, one should note too that there
> are many other implementations of closures in functional programming,
> and the property of creating pure functions is an absolutely key one.
> It's what allows referential transparency --- Main Property #1 !! :-)
> Rich Artym.
> Existing media are so disconnected from reality that our policy debates
> spin around a fantasy world in which the future looks far too much like
> the past. http://www.zyvex.com/nanotech/MITtecRvwSmlWrld/article.html
So it's the fact that assigments (i.e. set!) are allowed, not the
closure issue (since closures are handled the same way as scheme),
that make lua not a purely functional language?
"Seeking understanding through stupid questions"