[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: primitive eval with module => Unbound variable?
From: |
Andy Wingo |
Subject: |
Re: primitive eval with module => Unbound variable? |
Date: |
Wed, 17 May 2017 21:44:02 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) |
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).
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