guile-devel
[Top][All Lists]
Advanced

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

Re: Non-stack-copying call-with-current-continuation?


From: Andy Wingo
Subject: Re: Non-stack-copying call-with-current-continuation?
Date: Sat, 03 Mar 2012 18:41:17 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Hi David,

On Fri 02 Mar 2012 01:00, David Kastrup <address@hidden> writes:

> Is there a way to get a call-with-current-continuation that does not
> create a stack copy?

This is usually referred to as `call-with-escape-continuation'.

For example, here are Racket's words on the topic:

  
http://docs.racket-lang.org/reference/cont.html#(def._((quote._~23~25kernel)._call-with-escape-continuation))

Here is a good definition of call/ec in Guile:

  (define (call/ec proc)
    (let ((tag (make-prompt-tag)))
      (define (abort . args)
        (abort-to-prompt tag args))
      (call-with-prompt tag
        (lambda () (proc abort))
        (lambda (k args) (apply values args)))))

That one won't work in Guile 1.8 though.  A portable definition:

  (define (call/ec proc)
    (let ((key (gensym "escape ")))
      (define (abort . args)
        (throw key args))
      (catch key
        (lambda () (proc abort))
        (lambda (key args) (apply values args)))))

Regards,

Andy
-- 
http://wingolog.org/



reply via email to

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