unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neil@ossau.uklinux.net>
To: linasvepstas@gmail.com
Cc: Guile User <guile-user@gnu.org>
Subject: Re: continuation barriers
Date: Wed, 26 Aug 2009 22:24:29 +0100	[thread overview]
Message-ID: <87y6p6nu9e.fsf@arudy.ossau.uklinux.net> (raw)
In-Reply-To: <3ae3aa420908231319y6cd4d189l4c1cab0a6b24283f@mail.gmail.com> (Linas Vepstas's message of "Sun\, 23 Aug 2009 15\:19\:40 -0500")

Linas Vepstas <linasvepstas@gmail.com> 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	other threads:[~2009-08-26 21:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-23 20:19 continuation barriers Linas Vepstas
2009-08-26 21:24 ` Neil Jerram [this message]
2009-08-28 15:41   ` Linas Vepstas
2009-08-28 21:42   ` Linas Vepstas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y6p6nu9e.fsf@arudy.ossau.uklinux.net \
    --to=neil@ossau.uklinux.net \
    --cc=guile-user@gnu.org \
    --cc=linasvepstas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).