From: Hans Aberg <haberg-1@telia.com>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: hygiene and macro-introduced toplevel bindings
Date: Sun, 27 Feb 2011 23:02:05 +0100 [thread overview]
Message-ID: <D0C7AF2B-914A-477A-BC01-6A0FE28AE0F3@telia.com> (raw)
In-Reply-To: <m3ipw5rwex.fsf@unquote.localdomain>
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.
>
> The issue is in expressions like this:
>
> (define-syntax define-accessor
> (syntax-rules ()
> ((_ getter setter init)
> (begin
> (define val init)
> (define getter (lambda () val))
> (define setter (lambda (x) (set! val x)))
>
> (define-accessor get-x set-x! 0)
>
> The issue is, what happens when this expression is expanded?
>
> 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.
>
> 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.
>
> 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 <tuple>", and the value of <tuple> 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
next prev parent reply other threads:[~2011-02-27 22:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-27 21:37 hygiene and macro-introduced toplevel bindings Andy Wingo
2011-02-27 22:02 ` Hans Aberg [this message]
2011-02-28 0:15 ` Andreas Rottmann
2011-02-28 21:28 ` Andy Wingo
2011-02-28 21:49 ` Noah Lavine
2011-03-08 22:33 ` Andy Wingo
2011-02-28 22:32 ` Ludovic Courtès
2011-03-08 22:37 ` Andy Wingo
2011-03-09 9:33 ` Hans Aberg
2011-03-09 20:14 ` Andy Wingo
2011-04-04 13:48 ` Hans Aberg
2011-04-01 8:52 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D0C7AF2B-914A-477A-BC01-6A0FE28AE0F3@telia.com \
--to=haberg-1@telia.com \
--cc=guile-devel@gnu.org \
--cc=wingo@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).