From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Hans Aberg Newsgroups: gmane.lisp.guile.devel Subject: Re: hygiene and macro-introduced toplevel bindings Date: Sun, 27 Feb 2011 23:02:05 +0100 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1298844329 31421 80.91.229.12 (27 Feb 2011 22:05:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 27 Feb 2011 22:05:29 +0000 (UTC) Cc: guile-devel To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Feb 27 23:05:25 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ptojz-00064F-KN for guile-devel@m.gmane.org; Sun, 27 Feb 2011 23:05:23 +0100 Original-Received: from localhost ([127.0.0.1]:34680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ptojz-0000H1-1f for guile-devel@m.gmane.org; Sun, 27 Feb 2011 17:05:23 -0500 Original-Received: from [140.186.70.92] (port=56725 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ptogu-0005o9-8C for guile-devel@gnu.org; Sun, 27 Feb 2011 17:02:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ptogt-00065T-9M for guile-devel@gnu.org; Sun, 27 Feb 2011 17:02:12 -0500 Original-Received: from smtp-out11.han.skanova.net ([195.67.226.200]:38438) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ptogt-00065N-0t for guile-devel@gnu.org; Sun, 27 Feb 2011 17:02:11 -0500 Original-Received: from [10.0.1.2] (217.210.127.13) by smtp-out11.han.skanova.net (8.5.133) (authenticated as u26619196) id 4D6512CA0016F579; Sun, 27 Feb 2011 23:02:07 +0100 In-Reply-To: X-Mailer: Apple Mail (2.1082) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.67.226.200 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11723 Archived-At: On 27 Feb 2011, at 22:37, Andy Wingo wrote: > Andreas has been struggling with a nonstandard behavior of Guile's > recently, and we should discuss it more directly. >=20 > The issue is in expressions like this: >=20 > (define-syntax define-accessor > (syntax-rules () > ((_ getter setter init) > (begin > (define val init) > (define getter (lambda () val)) > (define setter (lambda (x) (set! val x))) >=20 > (define-accessor get-x set-x! 0) >=20 > The issue is, what happens when this expression is expanded? >=20 > Within a let or a lambda, it expands to an three internal definitions: > `val', `getter', and `setter', where `val' is only visible to within = the > `getter' and `setter' procedures. >=20 > At the top level, it expands to three definitions: "val", the getter, > and the setter. However in this case the "val" binding is global to = the > module, and can be referenced by anyone. >=20 > This is what happens in Guile. When implementing environments with returns and loops with break and = continue, I was not able to produce global symbols. This was under 1.8, = though, so perhaps it has changed. My solution was to introduce it as a variable in the macro, and then = generate it globally in my program, which generates Guile C-calls. This = is the example: ; Macro "environment": (environment return ...) puts the arguments ... = into ; a new environment, then evaluated as an imperative sequence; "return = x" causes ; x to be returned from the environment (define-syntax environment (syntax-rules () ((environment) (values)) ((environment return (x ...)) (call-with-current-continuation (lambda (return) x ...))) ((environment return label (x ...)) (call-with-current-continuation (lambda (return) (let ((label return)) x ...)))) )) Here, 'return', is just a variable. But I let the user to write "return = ", and the value of will become the return value of the = environment if called. There is a variation of the Guile 'while' statement. Then But it illustrates my problem: I would like a mechanism to control = whether a variable in a macro should be visible or not. It can be tied = in the macro in some lambda-expression, but one may want it visible = outside. - The construction is a bit too hygienic, in other words. Hans