[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Non-stack-copying call-with-current-continuation?
From: |
David Kastrup |
Subject: |
Re: Non-stack-copying call-with-current-continuation? |
Date: |
Fri, 02 Mar 2012 02:35:14 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) |
Noah Lavine <address@hidden> writes:
> Oh yes, you're right. I'm sorry I missed it.
>
> I believe you can do it hygienically though. With prompts, you can use
> (make-prompt-tag) to generate a new, unique tag. With catch and throw,
> you could use (gensym) to do the same thing. You first example would
> become something like
>
> (define-public (find-child music predicate)
> "Find the first node in @var{music} that satisfies @var{predicate}."
> (let ((music-found-tag (gensym)))
> (catch music-found-tag
> (lambda ()
> (fold-some-music predicate
> (lambda (music . _) (throw music-found-tag
> music))
> #f music))
> (lambda (key music) music)))
>
> Does that work?
Sure, but things like gensym and make-prompt-tag (and (list '()) for
creating an eq?-unique object) are artificial hygiene coming at a cost
in symbol table and symbol generation time rather than "lexical"
hygiene. They need _extra_ work, whereas the
call-with-current-continuation approach needed _less_ work. Basically I
want something like call-with-single-continuation that will only allow
one return (and any dynwind out counts and should work if it is the
first, so it is not exactly equivalent to using
with-continuation-barrier) and come without the stack-copying cost of
call-with-current-continuation.
Sure, you can do
(define (call-with-single-continuation proc)
(let ((tag (gensym)))
(catch tag
(proc (lambda x (throw tag x)))
(lambda (tag x) (apply values x)))))
Oops. (apply values ...)? Does this even work? Anyway, you get the
drift. But it is not pretty and it is not primitive. And its failure
mode when you disobey the "single" contract is an uncaught exception
with a weird symbol.
--
David Kastrup
- Non-stack-copying call-with-current-continuation?, David Kastrup, 2012/03/01
- Re: Non-stack-copying call-with-current-continuation?, Noah Lavine, 2012/03/01
- Re: Non-stack-copying call-with-current-continuation?, David Kastrup, 2012/03/01
- Re: Non-stack-copying call-with-current-continuation?, Noah Lavine, 2012/03/01
- Re: Non-stack-copying call-with-current-continuation?,
David Kastrup <=
- Re: Non-stack-copying call-with-current-continuation?, Noah Lavine, 2012/03/01
- Re: Non-stack-copying call-with-current-continuation?, David Kastrup, 2012/03/02
- Re: Non-stack-copying call-with-current-continuation?, Andreas Rottmann, 2012/03/03
- Re: Non-stack-copying call-with-current-continuation?, Andreas Rottmann, 2012/03/03
- Re: Non-stack-copying call-with-current-continuation?, Andy Wingo, 2012/03/03
- Re: Non-stack-copying call-with-current-continuation?, David Kastrup, 2012/03/04
- Re: Non-stack-copying call-with-current-continuation?, Andy Wingo, 2012/03/04
- Re: Non-stack-copying call-with-current-continuation?, David Kastrup, 2012/03/04
- Re: Non-stack-copying call-with-current-continuation?, Andy Wingo, 2012/03/04
- Re: Non-stack-copying call-with-current-continuation?, Mark H Weaver, 2012/03/04