[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: primitive eval with module => Unbound variable?
From: |
Jan Nieuwenhuizen |
Subject: |
Re: primitive eval with module => Unbound variable? |
Date: |
Thu, 18 May 2017 06:54:59 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) |
Andy Wingo writes:
> On Tue 16 May 2017 23:59, Jan Nieuwenhuizen <address@hidden> 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 <address@hidden> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.com