[Bese-devel] lambda and call/cc
Larry D'Anna
smoof-ra at elder-gods.org
Tue Jun 28 17:35:54 UTC 2005
* Marco Baringer (mb at bese.it) [050625 09:24]:
> Larry D'Anna <smoof-ra at elder-gods.org> writes:
>
> > If I understand it correctly, the reason you can't have a call/cc
> > inside a lambda is that then you have lambdas floating around that
> > needed to be called with the call/cc convention rather then the usual
> > one, and there's no way to tell them apart. If this is the case then
> > it should be possible to add operators lambda/cc and funcall/cc that
> > can be used to make and call cps lambdas. Am I on the right track
> > here?
>
> yes you are. however implmenenting funcall/cc correctly (or the more
> general apply/cc) will require you to, almost, reimplente lisp's
> execution semantics.
Are you sure? It seems to me that as long as you insist that the user
remember whether his functions are plain lambdas or lambda/cc's then
it's easy. I wrote it up and it seems to work. It's in the latest
revision (patch-3) of my local branch.
smoof-ra at elder-gods.org--stuff/arnesi--mine--1.4
at
http://elder-gods.org/~larry/tlastuff
I've added funcall/cc, apply/cc, and lambda/cc which are described
above. Also there's call/cc$ which expects a lambda/cc and behaves as
if *call/cc-returns* is true.
In that same revision is jump/cc which calls a user-visible continuation
(ie one make with make-call/cc-k) with scheme-like semantics; it never returns.
I haven't tested all this stuff extremely throughly, but it's nifty
and seems to work. For example:
(with-call/cc
(print (let/cc$ k
(print 'a)
(jump/cc k 'b)
(print 'c)
'd)))
will print a and b, and return b.
--larry
More information about the bese-devel
mailing list