This is the mail archive of the
guile@cygnus.com
mailing list for the Guile project.
Re: (lambda (foo) (some-c-function)) - can that C function get foo ?
- To: Martin Baulig <martin@home-of-linux.org>
- Subject: Re: (lambda (foo) (some-c-function)) - can that C function get foo ?
- From: Maciej Stachowiak <mstachow@alum.mit.edu>
- Date: 30 Jun 1999 15:47:17 -0400
- Cc: guile@sourceware.cygnus.com
- References: <867lolla2e.fsf@localhost.uni-trier.de>
Martin Baulig <martin@home-of-linux.org> writes:
> Hello guys,
>
> This is a strange subject for this mail, but it's also some "strange"
> problem.
>
> I'm using some C code like this:
>
> ====
> static SCM
> test (void)
> {
> return gh_eval_str ("foo");
> }
>
> void
> scm_init_gdb_gdb_module ()
> {
> gh_new_procedure ("testfunc", test, 0, 0, 0);
> }
> ====
>
> Then I try calling it in guile like this:
>
> ====
> (let ((foo "bar")) (testfunc))
> ====
>
> all I get is an "Unbound variable: foo" error. Same for the following:
>
> ====
> (define bar (lambda (foo) (testfunc)))
> (bar 10)
> ====
>
> This works without problems when I define "foo" in the top-level env
> like this:
>
> ====
> guile> (define foo "bar")
> guile> (testfunc)
> "bar"
> ====
>
> Is this a guile bug or am I doing something wrong ?
It's working as advertised, gh_eval_str evaluates in the top-level
environment. There are other functions to evaluate in the local
environment, but are you sure you really need to do that?
> In general, when you call a C function inside a (let ...) or a (lambda ...)
> expressions is it possible to access the variables that are defined locally
> in the scope of that expression ?
>
Well, why do you want to do that anyway? Surely there is a cleaner
solution to your problem.
- Maciej