From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.devel Subject: Re: syntax-local-value patch for discussion Date: Sat, 14 Jan 2012 17:42:58 +0100 Message-ID: References: <87fwfq6m5x.fsf@netris.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0015173ff8728a292604b67fac85 X-Trace: dough.gmane.org 1326559392 23598 80.91.229.12 (14 Jan 2012 16:43:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 14 Jan 2012 16:43:12 +0000 (UTC) Cc: guile-devel To: Mark H Weaver Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Jan 14 17:43:07 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Rm6h8-0000E3-MP for guile-devel@m.gmane.org; Sat, 14 Jan 2012 17:43:06 +0100 Original-Received: from localhost ([::1]:41804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rm6h8-00074x-1Q for guile-devel@m.gmane.org; Sat, 14 Jan 2012 11:43:06 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:44000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rm6h4-00074h-4b for guile-devel@gnu.org; Sat, 14 Jan 2012 11:43:03 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rm6h2-00036p-B5 for guile-devel@gnu.org; Sat, 14 Jan 2012 11:43:01 -0500 Original-Received: from mail-ey0-f169.google.com ([209.85.215.169]:35651) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rm6h2-00036i-2r for guile-devel@gnu.org; Sat, 14 Jan 2012 11:43:00 -0500 Original-Received: by eaan1 with SMTP id n1so568262eaa.0 for ; Sat, 14 Jan 2012 08:42:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=XGgfF80Qi10/XdP8Gh/sI6thnR36D6aJVyt2hYQHYGc=; b=fdKaXcHXK9Yoke3drfUapx7la2Hh3ZtxMzRYFl1Nnk6867B3EgoohiTtZoAppC71MY Msxp7xuXDq863caVHdTLc/LlBbYoiU+NcmGDCsPs79cBVJE+lyt2ChRi7gBtwTPVRitq EiOs0PJ8vFG6f92e4UpUUA7AA10tnkyU+dkus= Original-Received: by 10.213.110.2 with SMTP id l2mr1610720ebp.22.1326559378679; Sat, 14 Jan 2012 08:42:58 -0800 (PST) Original-Received: by 10.213.33.77 with HTTP; Sat, 14 Jan 2012 08:42:58 -0800 (PST) In-Reply-To: <87fwfq6m5x.fsf@netris.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.215.169 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:13499 Archived-At: --0015173ff8728a292604b67fac85 Content-Type: text/plain; charset=ISO-8859-1 Ok, I have tried follow your suggestion, here is what I could make, (with-fluids ((*macro-lookup* (lambda (e) (cond ((number? e) (pk w)) ((symbol? e) (lookup (id-var-name e w) r mod)) ((syntax-object? e) (lookup (id-var-name (syntax-object-expression e) (syntax-object-wrap e)) r (or (syntax-object-module e) mod))) (else #f))))) just look at the syntax-object? part for now. You will see that I only use syntax-object-wrap and not the joining with w which fails when I try to do that using e.g. ((syntax-object? e) (syntax-type (syntax-object-expression e) r (join-wraps w (syntax-object-wrap e)) (or (source-annotation e) s) rib (or (syntax-object-module e) mod) for-car?)) which is the syntax? part of the syntax-type function. Hence I tried (join-wraps w (syntax-object-wrap e)) but that does not work. comments? /Stefan On Sun, Jan 8, 2012 at 8:15 PM, Mark H Weaver wrote: > Hi Stefan, > > Stefan Israelsson Tampe writes: > > diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm > > index e522f54..70463a5 100644 > > --- a/module/ice-9/psyntax.scm > > +++ b/module/ice-9/psyntax.scm > > @@ -155,6 +155,10 @@ > > (eval-when (compile) > > (set-current-module (resolve-module '(guile)))) > > > > +(define *macro-lookup* (make-fluid)) > > +(fluid-set! *macro-lookup* > > + (lambda x (error "not in a macro evaluation context"))) > > + > > (let () > > (define-syntax define-expansion-constructors > > (lambda (x) > > @@ -1304,8 +1308,12 @@ > > (syntax-violation #f "encountered raw symbol in > macro output" > > (source-wrap e w (wrap-subst w) > mod) x)) > > (else (decorate-source x s))))) > > - (rebuild-macro-output (p (source-wrap e (anti-mark w) s mod)) > > - (new-mark)))) > > + (with-fluids ((*macro-lookup* > > + (lambda (e) (lookup (id-var-name e w) > > + r mod)))) > > + > > + (rebuild-macro-output (p (source-wrap e (anti-mark w) s mod)) > > + (new-mark))))) > > > > (define expand-body > > ;; In processing the forms of the body, we create a new, empty > wrap. > > This doesn't look quite right to me. > > At this one point only, where a macro is expanded, you capture the > lexical environment (r w mod) in your fluid. This is the lexical > environment that you use to lookup plain symbols later passed to > `syntax-binding-info'. > > Will this approach will be robust in the general case? For example, > what happens if you use a macro in one module to generate a macro in > another module that uses syntax-binding-info on a syntax object that > came from yet another module? > > A few suggestions: > > First, as others have pointed out, you should be passing syntax-objects > to `syntax-binding-info' instead of plain symbols. This one change > alone will make this code far robust, because syntax-objects include > their own wrap and module. > > Second, in your call to `lookup', you should pass the module that came > from the syntax-object, instead of the module captured from the most > recent macro expansion. Please take a look at how psyntax's internal > procedure `syntax-type' looks up syntax-objects (compared with how it > looks up plain symbols). I think you should emulate that logic. > > Third, are you sure that the `r' captured from the most recent macro > expansion will be recent enough in all cases to include the binding > that's being queried? `r' is extended in quite a few places in psyntax, > for various different binding constructs. > > Best, > Mark > --0015173ff8728a292604b67fac85 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Ok, I have tried follow your suggestion,
here is what I could make,
=
=A0=A0=A0=A0=A0=A0=A0 (with-fluids ((*macro-lookup*
=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (lambda (e)
=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (cond=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 ((number? e)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 (pk w))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ((symbol? e)
=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (lookup (id-var-name e = w)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 r mod))

=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ((syntax-object? e)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 (lookup (id-var-name
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (syntax-object= -expression e)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (syntax-object-wrap e))=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 r
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 (or
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (syntax-= object-module e)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 mod)))
=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (else #f)))= ))

just look at the syntax-object? part for now. You will see that I= only use
syntax-object-wrap and not the joining with w which fails when I try to do = that using e.g.
=A0((syntax-object? e)
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (s= yntax-type (syntax-object-expression e)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 r
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (join-wraps w (syntax-object-wrap e))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (or (sou= rce-annotation e) s) rib
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 (or (syntax-object-module e) mod) for-car?))

w= hich is the syntax? part of the syntax-type function. Hence I tried
(jo= in-wraps w (syntax-object-wrap e))

but that does not work.

comments?

/Stefan

On Sun, Jan 8, 2012 at 8:15 PM, Mark H Weaver <mhw@netris.org> wrote:
Hi Stefan,

Stefan Israelsson Tampe <stef= an.itampe@gmail.com> writes:
> diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm=
> index e522f54..70463a5 100644
> --- a/module/ice-9/psyntax.scm
> +++ b/module/ice-9/psyntax.scm
> @@ -155,6 +155,10 @@
> =A0(eval-when (compile)
> =A0 =A0(set-current-module (resolve-module '(guile))))
>
> +(define *macro-lookup* (make-fluid))
> +(fluid-set! *macro-lookup*
> + =A0 =A0 =A0 =A0 =A0 =A0(lambda x (error "not in a macro evaluat= ion context")))
> +
> =A0(let ()
> =A0 =A0(define-syntax define-expansion-constructors
> =A0 =A0 =A0(lambda (x)
> @@ -1304,8 +1308,12 @@
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (syntax-violation #f "enc= ountered raw symbol in macro output"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 (source-wrap e w (wrap-subst w) mod) x))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(else (decorate-source x s)))))=
> - =A0 =A0 =A0 =A0(rebuild-macro-output (p (source-wrap e (anti-mark w)= s mod))
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(new-mark= ))))
> + =A0 =A0 =A0 =A0(with-fluids ((*macro-lookup*
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (lambda (e) (lookup (id-= var-name e w)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 r mod))))
> +
> + =A0 =A0 =A0 =A0 =A0(rebuild-macro-output (p (source-wrap e (anti-mar= k w) s mod))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(new-= mark)))))
>
> =A0 =A0 =A0(define expand-body
> =A0 =A0 =A0 =A0;; In processing the forms of the body, we create a new= , empty wrap.

This doesn't look quite right to me.

At this one point only, where a macro is expanded, you capture the
lexical environment (r w mod) in your fluid. =A0This is the lexical
environment that you use to lookup plain symbols later passed to
`syntax-binding-info'.

Will this approach will be robust in the general case? =A0For example,
what happens if you use a macro in one module to generate a macro in
another module that uses syntax-binding-info on a syntax object that
came from yet another module?

A few suggestions:

First, as others have pointed out, you should be passing syntax-objects
to `syntax-binding-info' instead of plain symbols. =A0This one change alone will make this code far robust, because syntax-objects include
their own wrap and module.

Second, in your call to `lookup', you should pass the module that came<= br> from the syntax-object, instead of the module captured from the most
recent macro expansion. =A0Please take a look at how psyntax's internal=
procedure `syntax-type' looks up syntax-objects (compared with how it looks up plain symbols). =A0I think you should emulate that logic.

Third, are you sure that the `r' captured from the most recent macro expansion will be recent enough in all cases to include the binding
that's being queried? =A0`r' is extended in quite a few places in p= syntax,
for various different binding constructs.

=A0 =A0 =A0Best,
=A0 =A0 =A0 Mark

--0015173ff8728a292604b67fac85--