unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: syntax-local-value patch for discussion
Date: Sun, 08 Jan 2012 14:15:22 -0500	[thread overview]
Message-ID: <87fwfq6m5x.fsf@netris.org> (raw)
In-Reply-To: <CAGua6m0syo=-jz9rxfcPr4NTuirRPFevZ89wHKVF_zi3OAgbig@mail.gmail.com> (Stefan Israelsson Tampe's message of "Mon, 5 Dec 2011 19:12:28 +0100")

Hi Stefan,

Stefan Israelsson Tampe <stefan.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 @@
>  (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



  parent reply	other threads:[~2012-01-08 19:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-05 18:12 syntax-local-value patch for discussion Stefan Israelsson Tampe
2011-12-08 21:58 ` Ian Price
2011-12-09 11:49   ` Stefan Israelsson Tampe
2012-01-07  0:05 ` Andy Wingo
2012-01-08 17:47   ` Stefan Israelsson Tampe
2012-01-08 19:15 ` Mark H Weaver [this message]
2012-01-08 21:28   ` Stefan Israelsson Tampe
2012-01-14 16:42   ` Stefan Israelsson Tampe
2012-01-19  9:50     ` Stefan Israelsson Tampe
2012-01-23 10:53       ` Andy Wingo
2012-01-23 16:06         ` Stefan Israelsson Tampe
2012-01-26 11:31           ` Andy Wingo
2012-01-26 15:49             ` Stefan Israelsson Tampe

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=87fwfq6m5x.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=stefan.itampe@gmail.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).