Andy Wingo writes: > On Tue 16 May 2017 23:59, Jan Nieuwenhuizen <[email protected]> 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 <[email protected]> | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.com
