This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: fluid-let


> > > Now on to with-fluids...
> > 
> > And after that you might want to try to express fluid-let with
> > defmacro but *without* gensym, while still being referential
> > transparent.
> 
> <ignorance>
> Why is it important to get rid of gensym?  Where can I find an
> understandable definition of 'referential transparency'?
> </ignorance>

You can't.  Referential transparency is like Satori.  Your mind
can internalize the concept, but not communicate it.  The only
way to acquire understanding is Sudden Enlightenment.

Nevertheless, here are a couple of attempts:

1) Referential Transparency is kind of like Freedom From Side Effects.
   An expression that doesn't produce any side effects can be said to
   be referentially transparent.

2) Referential Transparency means that anywhere an identifier is used,
   you could replace the identifier with the expression that initialized
   it and not change the meaning of the program.  In a referentially 
   transparent language, identifiers are more like abstract shorthands
   for expressions, and less like names for slots in memory.  So pure
   functional languages are r.t., but most common languages are not.
   Example, with C on the left and Scheme on the right:

        int x = 7;                    (define x 7)
        int y = ++x;                  (define y (begin (set! x (+ x 1)) x))
        int a = y + y;                (define a (+ y y))

    is _not_ equivalent to 

        int x = 7;                    (define x 7)
        int a = (++x) + (++x);        (define a (+ (begin (set! x (+ x 1)) x)
                                                   (begin (set! x (+ x 1)) x)))

    or worse yet,

        int a = (++7) + (++7);        (define a (+ (begin (set! 7 (+ 7 1)) 7)
                                                   (begin (set! 7 (+ 7 1)) 7)))

Being a functional language, it's easier to strive for referential 
transparency in Scheme than in C.  But sometimes it's easier to have
a ten line side-effecting transgression that avoids a hundred lines
of really elegant referentially transparent code.  I didn't look 
closely enough at your macro to know which is appropriate here.

-- 
Craig.              http://www.cs.washington.edu/homes/csk/
Counterfactuals: what would the world be like without them?