unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Noah Lavine <noah.b.lavine@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: CPS Update
Date: Tue, 19 Feb 2013 11:21:03 -0500	[thread overview]
Message-ID: <871uccgtqo.fsf@tines.lan> (raw)
In-Reply-To: <CA+U71=POy-eKqjSvrH39ohQfqr3r5PhQ1J5FpUymcekJAVh+ng@mail.gmail.com> (Noah Lavine's message of "Tue, 19 Feb 2013 10:51:47 -0500")

Noah Lavine <noah.b.lavine@gmail.com> 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	other threads:[~2013-02-19 16:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-16  0:53 CPS Update Noah Lavine
2013-02-16  7:39 ` Stefan Israelsson Tampe
2013-02-16 16:29   ` Noah Lavine
2013-02-16 19:14     ` Mark H Weaver
2013-02-16 19:36       ` Noah Lavine
2013-02-16 21:18         ` Mark H Weaver
2013-02-19 15:51           ` Noah Lavine
2013-02-19 16:21             ` Mark H Weaver [this message]
2013-02-22  8:25               ` William ML Leslie
2013-02-23  7:49                 ` Mark H Weaver
2013-02-25  4:54                   ` William ML Leslie
2013-02-26 10:24                     ` Mark H Weaver
2013-02-19 17:29     ` Stefan Israelsson Tampe
2013-03-08 22:57 ` Noah Lavine
2013-03-09  8:31   ` Andy Wingo
2013-04-03 20:50     ` Noah Lavine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871uccgtqo.fsf@tines.lan \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=noah.b.lavine@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).