Re: Continuations and dynamic variables
- From: Mariano Montone <marianomontone@xxxxxxxxx>
- Date: Fri, 20 Mar 2009 17:53:47 -0700 (PDT)
Talking to myself, but anyway...
What I meant was the whole dynamic binding structures are lost, of
course.
Using conditions for example:
(require :cl-cont)
(use-package :cl-cont)
(define-condition unhandled-condition (error)
())
(defvar *cont*)
(with-call/cc
(handler-case
(progn
(call/cc (lambda (cont)
(setf *cont* cont)))
(error 'unhandled-condition))
(unhandled-condition () (print "Condition handled!"))))
(funcall *cont*)
That signals a condition that doesn't get caught. I know that's
because when we do (funcall *cont*) we are in a different dynamic
environment.
Just wonder which is the correct semantic, and whether it is possible
to implement something that executes the continuation in the dynamic
environment it was generated somehow.
Btw, the continuation library seems to be buggy, so my experiments may
mean nothing:
This doesn't handle the condition, although I think it should:
(with-call/cc
(handler-case
(error 'unhandled-condition)
(unhandled-condition () (print "Condition handled!"))))
Mariano
On 20 mar, 17:23, Mariano Montone <marianomont...@xxxxxxxxx> wrote:
Hello,
I'd like to know how dynamic variables are supposed to
behave when using continuations. The way to implement continuations in
CL is by code transformation where the lambdas generated represent the
rest of the computation. The problem I see with this is that dynamic
variable bindings are not preserved.
For example, using the cl-cont package that works like that:
(require :cl-cont)
(use-package :cl-cont)
(defvar *my-dyn-var*)
(defvar *cont*)
(with-call/cc
(let
((*my-dyn-var* "hello!!"))
(call/cc (lambda (cont)
(setf *cont* cont)))
(print *my-dyn-var*)))
(funcall *cont*)
That prints nil instead of hello!! (the dynamic variable binding is
lost).
So, which is the correct semantic??
If our language were interpreted and we had access to the stack-
frames, we could get rid of the code transformation and implement
continuations copying stack-frames instead. This way, dynamic variable
bindings are preserved, which is interesting for programming some web
applications. AFAIK, this is how Seaside implement them, so I guess
they don't have that problem.
Thoughts?
Thanks!
Mariano
.
- References:
- Continuations and dynamic variables
- From: Mariano Montone
- Continuations and dynamic variables
- Prev by Date: Re: Help with a problem
- Next by Date: Re: Question regarding functions
- Previous by thread: Continuations and dynamic variables
- Next by thread: Re: Continuations and dynamic variables
- Index(es):
Relevant Pages
|