unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* order of evaluation
@ 2013-06-17 10:10 Andy Wingo
  2013-06-17 13:49 ` Noah Lavine
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Andy Wingo @ 2013-06-17 10:10 UTC (permalink / raw)
  To: guile-devel

I really enjoy the unspecified order of evaluation that Scheme has, but
perhaps that's an implementor's perspective.  So I thought that when we
went to convert to an intermediate form that names all intermediary
values like ANF or CPS, that we'd be able to preserve this; but it turns
out that it's not possible with ANF:

This transformation for example is incorrect:

  (foo (a (b)) (c (d)))

  => (let ((B (b)) (D (d)))
       (let ((A (a B)) (C (c D)))
         (foo A C)))

This is incorrect because it interleaves evaluation of the first and
second argument, which is not permitted by Scheme, and is silly anyway:
it introduces order-of-evaluation restrictions: evaluation of (d) and (a
B) is not specified in the original form, but is in this second form.

The normal way to do ANF is to choose an evaluation order:

  (let* ((B (b))
         (A (a B))
         (D (d))
         (C (c D)))
    (foo A C))

This is better from a CSE perspective, but it does fix order of
evaluation.

Preserving order of evaluation agnosticism would be possible in a more
direct-style IL:

  (let ((A (let ((B (b))) (a B)))
        (C (let ((D (d))) (c D))))
    (foo A C))

Not sure what to do.  The part of me that wants to do aggressive CSE
wants to transform to a form that fixes order of evaluation, but the
part of me that wants to be able to shuffle values using the Dybvig
algorithm wants to do the direct form.  Dunno!

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-07-03 18:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-17 10:10 order of evaluation Andy Wingo
2013-06-17 13:49 ` Noah Lavine
2013-06-17 20:14   ` Andy Wingo
2013-06-18  0:39     ` Noah Lavine
2013-06-18  1:06     ` William ML Leslie
2013-06-23 13:46 ` Ludovic Courtès
2013-07-03 18:57 ` order of evaluation, letrec-values, and define-values Mark H Weaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).