unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Jan Nieuwenhuizen <janneke@gnu.org>
Cc: guile-user@gnu.org
Subject: Re: primitive eval with module => Unbound variable?
Date: Wed, 17 May 2017 21:44:02 +0200	[thread overview]
Message-ID: <8737c3nu9p.fsf@pobox.com> (raw)
In-Reply-To: <87ziec4g62.fsf@gnu.org> (Jan Nieuwenhuizen's message of "Tue, 16 May 2017 23:59:01 +0200")

On Tue 16 May 2017 23:59, Jan Nieuwenhuizen <janneke@gnu.org> writes:

> This code works when not put in a module; make it a module and I get
>
>     => ERROR: Unbound variable: bar

I assume you mean that this doesn't work:

  (define-module (foo) #:export (baz))
  (define bar 42)
  (define (baz) (primitive-eval 'bar))

Then from another module you do (use-modules (foo)) and try to (baz).

The thing is that primitive-eval evaluates its expression with respect
to the current module.  The current module when you do (use-modules
(foo)) isn't (foo) -- it's the importing module.

This is the right thing:

  (define-module (foo) #:export (baz))
  (define eval-module (current-module)
  (define bar 42)
  (define (baz) (eval 'bar eval-module))

Cheers,

Andy



  parent reply	other threads:[~2017-05-17 19:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-16 21:59 primitive eval with module => Unbound variable? Jan Nieuwenhuizen
2017-05-17 17:58 ` Vladimir Zhbanov
2017-05-17 19:44 ` Andy Wingo [this message]
2017-05-18  4:54   ` Jan Nieuwenhuizen
2017-05-22 19:45     ` Andy Wingo
2017-05-22 20:19       ` Jan Nieuwenhuizen
2017-05-22 19:48     ` Andy Wingo

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=8737c3nu9p.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-user@gnu.org \
    --cc=janneke@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).