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 <m...@netris.org> wrote: > Hi Stefan, > > Stefan Israelsson Tampe <stefan.ita...@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 >