Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

question about call/cc theory

2 views
Skip to first unread message

Nathan Thern

unread,
Jan 31, 2007, 6:08:42 PM1/31/07
to
Fellow Schemers -
I am pondering a little thought experiment in which the result of a
call/cc is delivered along with other values. Consider the following
expression:

(let ((x 10) (y 100))
(call-with-values
(lambda ()
(values
(begin
(display "evaluating a")(newline)
x)
(call-with-current-continuation
(lambda (k)
(display "evaluating continuation")(newline)
(cons k 0)))
(begin
(display "evaluating c")(newline)
y)))
(lambda (a b c)
(display a)(newline)
(display c)(newline)
(set! x (+ x 10))
(set! y (+ y 100))
(if (> 2 (cdr b))
((car b) (cons (car b) (+ (cdr b) 1)))
#f))))

mzscheme produces the following output:
evaluating a
evaluating continuation
evaluating c
10
100
evaluating c
10
200
evaluating c
10
300
#f

SXM, on the other hand, evaluates arguments last-to-first; sxi produces:
evaluating c
evaluating continuation
evaluating a
10
100
evaluating a
20
100
evaluating a
30
100
#f

Both are equally valid outputs. And this would also be a valid output:
evaluating continuation
evaluating a
evaluating c
10
100
evaluating a
evaluating c
20
200
evaluating a
evaluating c
30
300
#f

However, would this be a valid output?:
evaluating continuation
evaluating a
evaluating c
10
100
10
100
10
100
#f

In other words, could a RNRS compliant optimizing scheme compiler
realize when the continuation is re-entered that it has already computed
two of the values and not compute them again regardless of the order in
which they were computed the first time?

(I am talking about compliance with RNRS and the theory/spirit of scheme
here. I am sure such a compiler is possible.)

0 new messages