unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Rob Browning <rlb@defaultvalue.org>
Cc: guile-user@gnu.org
Subject: Re: guile's eval from C
Date: Mon, 30 Sep 2002 11:47:38 -0500	[thread overview]
Message-ID: <87elbbfmqd.fsf@raven.i.defaultvalue.org> (raw)
In-Reply-To: <15767.26838.537408.102758@shmyh.ua> (Viktor Pavlenko's message of "Sun, 29 Sep 2002 16:55:50 -0400")

Viktor Pavlenko <vvp@rogers.com> writes:

> I'd like to evaluate an SCM object from C, equivalent to
>
> guile> (eval '(car '("a" "b" "c")))
> "a"
> guile> (eval "a")
> "a"

  SCM mylist = gh_eval_str ("(car '(\"a\" \"b\" \"c\"))");

or depending on your needs, perhaps:

  SCM somelist = SCM_EOL;
  ...
  mylist = scm_cons (scm_makfrom0str ("c"), somelist);
  ...
  mylist = scm_cons (scm_makfrom0str ("b"), somelist);
  ...
  mylist = scm_cons (scm_makfrom0str ("a"), somelist);
  ...
  SCM result = SCM_CAR (somelist);

This presumes you're using 1.6.0.  If you're not, then you may have to
substitute some gh_* functions for the above...

> Looks like the best way is to call gh_call1(), but how do I get an SCM
> object for guile's eval? I could also build a C string containing the
> complete expression to be evaluated ( "(eval '(car '("a" "b" "c")))" )
> and call gh_eval_str() but this seems inefficient because I have the
> expression to be evaluated as SCM object.

Alternately, I believe you could use this:

  scm_eval (some_expression, scm_c_resolve_module ("some module"));

though I haven't tested it and so the resolve_module call may need a
little adjustment...

Hope this helps.

-- 
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C  64AE 78FE E5FE F0CB A0AD


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


  reply	other threads:[~2002-09-30 16:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-29 20:55 guile's eval from C Viktor Pavlenko
2002-09-30 16:47 ` Rob Browning [this message]
2002-09-30 18:38 ` Neil Jerram
2002-09-30 19:36   ` Viktor Pavlenko

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=87elbbfmqd.fsf@raven.i.defaultvalue.org \
    --to=rlb@defaultvalue.org \
    --cc=guile-user@gnu.org \
    /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).