lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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