[plt-scheme] to define, or to let

From: Joe Marshall (jrm at ccs.neu.edu)
Date: Tue Mar 23 09:36:18 EST 2004

Paul Graunke <ptg at ccs.neu.edu> writes:

> I just want to say that I do not understand why anyone would want
> to program in a language without a well-defined meaning for each
> program.  

I don't.  I want to program in a language with a well-defined meaning
for each *correct* program.  I don't care about the meaning of
incorrect programs.

I *do* want to program in a language where this:

(foo (simple-expression a)
     (hairy-expression
       (with-nested-hairy-constructs
         (calling-other-complicated-things b))))

is equivalent to this:

(let ((hairy-result (hairy-expression
                      (with-nested-hairy-constructs
                        (calling-other-complicated-things b)))))
  (foo (simple-expression a) hairy-result))

As Scheme is defined today, it is an error for these two expressions
to not be equivalent.  It is true that it is impossible in general to
*detect* this error, but if the code is correct, the meaning is
preserved, and if the code is incorrect, the meaning may change from
one incorrect value to a different incorrect value.  Frankly, I'm not
very much interested in the return value of incorrect code.

By fixing the order of evaluation from left to right, the two
fragments of code above are *defined* to be non-equivalent.  This has
the `benefit' of taking one half of the space of formerly incorrect
code and defining it to be correct (although poor style).  It is still
impossible to *detect* this situation.  The drawback is that the
simple rewrite above is incorrect because it can change the meaning of
`correct' code --- *artificially* correct code because we all agree it
is poor style and probably accidental to depend on the order.

> Also, trying to debug you code with optimization turned off or
> extra print statements that mess up the optimizer and having everything
> work fine and then removing the debugging flags and/or print statements
> only to see the program cease to function properly is really quite
> annoying.

Unfortunately, fixing the order of evaluation does not solve this
problem.  The last time I encountered an order of evalution bug was
when I was using Common Lisp, which *has* a fixed order of
evaluation.

> Sure, one can claim that a programmer should write only code that
> is independent of evaluation order (baring time and space consumption).
> The question I have then is, how can I tell?  Did I write my code
> so that it is independent of evaluation order, or did I mess up?
> If the compiler writer cannot write a static analysis that can tell,
> how am I supposed to know?  

These are good questions.  However, you haven't shown how fixing the
order of evaluation answers them.  You still cannot tell, you still
may have messed up.




Posted on the users mailing list.