[plt-scheme] Continuation barriers and C extensions

From: Daniel Silva (daniel.silva at gmail.com)
Date: Tue Nov 23 07:16:58 EST 2004

Hi,

I'm not understanding something about continuation barriers.  The
following code works:

(define f
   (make-py-function
       (lambda (x)
         (call/cc
               (lambda (cc) (cc x))))))

(py-apply f (make-py-number 2))

... where the make-py-* functions go into C to wrap scheme values
inside Python objects (and wrap the Python objects inside Scheme cptr
objects on return).  Py-apply goes to C, unwraps the function object,
and calls MzScheme's scheme_apply.

But the function 'g' gives me an error:

(define (py-call/cc py-fn)
  (let/cc k
    (py-apply py-fn (make-py-function k))))

(define pycallcc (make-py-function py-call/cc))

(define g
   (make-py-function
       (lambda (x)
         (py-apply
           pycallcc
           (make-py-function
               (lambda (cc) (py-apply cc x)))))))

(py-apply g (make-py-number 2))

--------Errortrace--->
continuation application: attempted to cross a continuation barrier
stdin::5243: (py-apply cc x)
stdin::5156: (py-apply pycallcc (make-py-function (lambda (cc)
(py-apply cc ....))))
stdin::5857: (py-apply g (make-py-number 2))

as does this function:

  (define h
   (make-py-function
       (lambda (x)
         (py-call/cc
           (make-py-function
               (lambda (cc) (py-apply cc x)))))))  

(py-apply h (make-py-number 2))

--------Errortrace--->
continuation application: attempted to cross a continuation barrier
stdin::5538: (py-apply cc x)
stdin::5469: (py-call/cc (make-py-function (lambda (cc) (py-apply cc x))))
stdin::5660: (py-apply h (make-py-number 2))


Is there any way to call a continuation from C?

Daniel


Posted on the users mailing list.