guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: continuation barriers


From: Neil Jerram
Subject: Re: continuation barriers
Date: Wed, 26 Aug 2009 22:24:29 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Linas Vepstas <address@hidden> writes:

> i.e. I'd like something like this to work:
>
> scm_c_eval_string(" ... (call/cc (lambda (k) (set! *myk* k))) ...");
> ... some_c_code(...);
> scm_c_eval_string(" ... (*myk* 42) ...");

I think there are a couple of problems here.

The first is as you've noted, that scm_c_eval_string() has a
scm_c_with_continuation_barrier() hiding inside it.  You can avoid
that by using some other method for calling from C into Scheme, for
example:

(define (entry-point code)
  ... set up whatever catches you want around the 
      code that is going to be evaluated, e.g. for
      debugging ...
  (eval (with-input-from-string code read) (current-module))
  ...)

SCM entry_point_proc = SCM_VARIABLE_REF (scm_c_lookup ("entry-point"));

scm_call_1 (entry_point_proc, code_string);

The second is that you almost certainly don't want the continuation
call to make C think it is returning again from the first scm_call_1
().  That kind of thing tends to confuse C code :-)

I solved that problem (when I wanted to do something very like what
you're doing) with an approach like this:

(define current-c-code-continuation #f)

(define (entry-point code)
  (call/cc (lambda (k)
             (set! current-c-code-continuation k)

             ... set up ... (as above) ...
             (eval (with- ...) ...)
             ... (as above)

             (current-c-code-continuation))))

> I think (I haven't yet tried) that the above can work if I wrap
> the whole darn thing with scm_with_guile() .. but is there
> some way of getting the above to run without a big wrap
> of this kind?

I don't think the above qualifies as "without a big wrap".  But it did
work.

Regards,
        Neil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]