From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Jan Nieuwenhuizen Newsgroups: gmane.lisp.guile.user Subject: Re: primitive eval with module => Unbound variable? Date: Thu, 18 May 2017 06:54:59 +0200 Organization: AvatarAcademy.nl Message-ID: <87shk24vdo.fsf@gnu.org> References: <87ziec4g62.fsf@gnu.org> <8737c3nu9p.fsf@pobox.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1495083348 8968 195.159.176.226 (18 May 2017 04:55:48 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 18 May 2017 04:55:48 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: guile-user@gnu.org To: Andy Wingo Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu May 18 06:55:40 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBDTP-00026d-5P for guile-user@m.gmane.org; Thu, 18 May 2017 06:55:39 +0200 Original-Received: from localhost ([::1]:51735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBDTQ-0005kx-VM for guile-user@m.gmane.org; Thu, 18 May 2017 00:55:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBDT1-0005ki-M1 for guile-user@gnu.org; Thu, 18 May 2017 00:55:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBDSy-0006xO-M8 for guile-user@gnu.org; Thu, 18 May 2017 00:55:15 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:45628) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBDSp-0006sM-4T; Thu, 18 May 2017 00:55:03 -0400 Original-Received: from peder.onsbrabantnet.nl ([88.159.206.46]:37028 helo=dundal.peder.onsbrabantnet.nl) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dBDSo-0001wT-Bm; Thu, 18 May 2017 00:55:02 -0400 X-Url: http://AvatarAcademy.nl In-Reply-To: <8737c3nu9p.fsf@pobox.com> (Andy Wingo's message of "Wed, 17 May 2017 21:44:02 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13725 Archived-At: Andy Wingo writes: > On Tue 16 May 2017 23:59, Jan Nieuwenhuizen writes: > >> This code works when not put in a module; make it a module and I get >> >> =3D> 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 ev= al-module))) So (current-module) is not the defining model (foo) in these cases. Greetings, janneke --=20 Jan Nieuwenhuizen | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar=C2=AE http://AvatarAcademy.com