guile-devel
[Top][All Lists]
Advanced

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

Re: CPS Update


From: Mark H Weaver
Subject: Re: CPS Update
Date: Tue, 19 Feb 2013 11:21:03 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Noah Lavine <address@hidden> writes:
> But before we continue, are you sure that the right semantics is to
> modify all of the continuations? In particular, let's say you have a
> function like this:
>
> (define (func x)
>   (+ x 2 (my-special-function x)))
>
> And my-special-function captures its continuation, k. Later on, you
> modify func to be this:
>
> (define (func x)
>   (+ x 2))
>
> Now what is the continuation k supposed to do? That continuation
> doesn't exist in the latest version of func. I think in this case you
> have to treat it like a closure that is still holding on to the
> continuation that it was passed (conceptually, at least) when it was
> called. So it would return to the old version of func.

Yes.  If you redefine 'func', that only affects future calls to func,
not existing calls.

> On the other hand, take the same example, but this time redefine "+"
> instead of "func". Now, does the continuation k call the new
> definition of +, or the old one?

In your example above, it's unspecified, because the operator and
operands of a procedure call are evaluated in unspecified order.
Therefore, an implementation is allowed to evaluate '+' either before or
after it evaluates (my-special-function x).

However, consider this slightly different example:

(define (func x)
  (let ((r (my-special-function x)))
    (+ x 2 r)))

Here, (my-special-function x) must be evaluated before evaluating '+'.
Evaluating '+' means to fetch the value stored in the location denoted
by '+'.  Therefore, if '+' is rebound during the call to
'my-special-function', then the new binding for '+' must be used.

This is a case where on-stack-replacement is needed to implement the
correct semantics.

To summarize, when you rebind a function 'foo', it is not the existing
activation records for 'foo' that you need to worry about.  Instead, you
need to worry about existing activation records for all compiled
procedures 'bar' that incorporated assumptions about 'foo'.

Thanks for working on this,

     Mark



reply via email to

[Prev in Thread] Current Thread [Next in Thread]