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

Andy Wingo writes:

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

Yes.

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

Okay...

> This is the right thing:
>
>   (define-module (foo) #:export (baz))
>   (define eval-module (current-module))
>   (define bar 42)
>   (define (baz) (eval 'bar eval-module))

Thanks!...this works.  I'm very happy with this, it means that I can
create an sexp-object format, yay!

Earlier I tried several things eval, but did not see this `define
eval-module' coming.  The above works, this does not work

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

and neither does this work

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

So (current-module) is not the defining model (foo) in these cases.

Greetings,
janneke

-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com



  reply	other threads:[~2017-05-18  4:54 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
2017-05-18  4:54   ` Jan Nieuwenhuizen [this message]
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=87shk24vdo.fsf@gnu.org \
    --to=janneke@gnu.org \
    --cc=guile-user@gnu.org \
    --cc=wingo@pobox.com \
    /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).