unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* guile's eval from C
@ 2002-09-29 20:55 Viktor Pavlenko
  2002-09-30 16:47 ` Rob Browning
  2002-09-30 18:38 ` Neil Jerram
  0 siblings, 2 replies; 4+ messages in thread
From: Viktor Pavlenko @ 2002-09-29 20:55 UTC (permalink / raw)


Hello and sorry for the simple question.

I'd like to evaluate an SCM object from C, equivalent to

guile> (eval '(car '("a" "b" "c")))
"a"
guile> (eval "a")
"a"

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.

Thank you in advance.

Viktor


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: guile's eval from C
  2002-09-29 20:55 guile's eval from C Viktor Pavlenko
@ 2002-09-30 16:47 ` Rob Browning
  2002-09-30 18:38 ` Neil Jerram
  1 sibling, 0 replies; 4+ messages in thread
From: Rob Browning @ 2002-09-30 16:47 UTC (permalink / raw)
  Cc: guile-user

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: guile's eval from C
  2002-09-29 20:55 guile's eval from C Viktor Pavlenko
  2002-09-30 16:47 ` Rob Browning
@ 2002-09-30 18:38 ` Neil Jerram
  2002-09-30 19:36   ` Viktor Pavlenko
  1 sibling, 1 reply; 4+ messages in thread
From: Neil Jerram @ 2002-09-30 18:38 UTC (permalink / raw)
  Cc: guile-user

>>>>> "Viktor" == Viktor Pavlenko <vvp@rogers.com> writes:

    Viktor> Hello and sorry for the simple question.
    Viktor> I'd like to evaluate an SCM object from C, equivalent to

    guile> (eval '(car '("a" "b" "c")))
    Viktor> "a"
    guile> (eval "a")
    Viktor> "a"

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

One possibility is:

  scm_primitive_eval (exp);

This will evaluate the supplied expression in the current module.

Does this help?

        Neil



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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: guile's eval from C
  2002-09-30 18:38 ` Neil Jerram
@ 2002-09-30 19:36   ` Viktor Pavlenko
  0 siblings, 0 replies; 4+ messages in thread
From: Viktor Pavlenko @ 2002-09-30 19:36 UTC (permalink / raw)
  Cc: guile-user

>>>>> "NJ" == Neil Jerram <neil@ossau.uklinux.net> writes:

>>>>> "Viktor" == Viktor Pavlenko <vvp@rogers.com> writes:
    Viktor> Hello and sorry for the simple question.
    Viktor> I'd like to evaluate an SCM object from C, equivalent to

    guile> (eval '(car '("a" "b" "c")))
    Viktor> "a"
    guile> (eval "a")
    Viktor> "a"

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

    NJ> One possibility is:

    NJ>   scm_primitive_eval (exp);

    NJ> This will evaluate the supplied expression in the current module.

    NJ> Does this help?

I believe it will when I switch to 1.6. Thanks!

Viktor


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-09-30 19:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-29 20:55 guile's eval from C Viktor Pavlenko
2002-09-30 16:47 ` Rob Browning
2002-09-30 18:38 ` Neil Jerram
2002-09-30 19:36   ` Viktor Pavlenko

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).