guile-user
[Top][All Lists]
Advanced

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

Re: guile's eval from C


From: Rob Browning
Subject: Re: guile's eval from C
Date: Mon, 30 Sep 2002 11:47:38 -0500
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2 (i386-pc-linux-gnu)

Viktor Pavlenko <address@hidden> 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




reply via email to

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