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

RE: Y Store /Closures



Jacob Matthews wrote:

> On Mon, 17 Mar 2003, Anton van Straaten wrote:
>
> > [order of evaluation is] only an important detail of the semantics in a
> > language with side effects, of course ...
>
> I'm not sure about that. Seems to me that the Scheme program
>
> (let/cc k ((lambda (x y) x) (k 'left-to-right) (k 'right-to-left)))
>
> produces 'left-to-right if evaluation goes from left to right, and
> 'right-to-left if evaluation goes from right to left, even though it
> doesn't employ side-effects.

What's your definition of a side-effect?  I consider invoking a continuation
to *be* a side-effect, because it violates referential transparency, by
abandoning the current continuation.  I would define a side-effect as
anything which violates referential transparency, which is a bit more
general than definitions that focus on issues like assignment, I/O, or
"modifying state".

If you substitute a subexpression which invokes a continuation with the
result of evaluating that subexpression (i.e. invoking the continuation),
the overall expression will not necessarily (or usually) have the same
result.  For continuations to be referentially transparent, they would have
to return to where they were invoked.  In that case, the above expression
would always evaluate to the value of (k 'left-to-right), and wouldn't tell
you anything about evaluation order.

For a poetic take on this, see the Haskell Lover's Plea at
http://www.haskell.org/humor/poem.html :

      ...
      Restrain yourself! And you too will see
      The wondrous and refined joys of referential transparency!

   Alas, I can do without goto, without call/cc.
   But sans side-effects, I am lost and forlorn, can't you see?
   ...

Anton