Email or username:

Password:

Forgot your password?
Andrew Tropin

How to delimit an undelimited continuation?

I want something like this to work without going into infinite loop (I don't want call/cc to capture context outside of quoted code):

(begin
(define (my-eval exp)
"Maybe some other eval implementation here?"
(primitive-eval exp))

(my-eval `(define kont #f))
(my-eval `(+ 1 (call/cc (lambda (k) (set! kont k) 5))))
(my-eval `(kont 41)))

#guile #scheme #lisp

4 comments
Andy Wingo

@abcdw see call/cc definition in (hoot prelude)

Andrew Tropin

@wingo Thank you, I'll take a look!

ATM I worked around it like this:

(begin
(define (my-call/cc f)
(shift k (k (f k))))

(define (my-eval exp)
(reset
(primitive-eval exp)))

(my-eval `(define kont #f))
(my-eval `(+ 1 (my-call/cc (lambda (k) (set! kont k) 5))))
(my-eval `(kont 41)))

But don't know how good this idea is :)

I have another plan on how to improve the evaluation thread implementation, so call/cc doesn't break the value returning and interruption mechanisms.

@wingo Thank you, I'll take a look!

ATM I worked around it like this:

(begin
(define (my-call/cc f)
(shift k (k (f k))))

(define (my-eval exp)
(reset
(primitive-eval exp)))

(my-eval `(define kont #f))
(my-eval `(+ 1 (my-call/cc (lambda (k) (set! kont k) 5))))
(my-eval `(kont 41)))

But don't know how good this idea is :)

Andrew Tropin

@wingo It seems to preserve the semantics of call/cc, but probably there are some shortcomings in this implementation.

P.S. Oops, it doesn't preserve the semantics.

Andrew Tropin

@wingo I like the idea to make a default-prompt-tag a parameter: gitlab.com/spritely/guile-hoot

I also find your implementation quite similiar to what I tried to do with shift/reset above.

Thank you for sharing!

Go Up