So I tried to get hold of the macro binding. So with the following patch wich should be enogh for me to make progress porting rackets syntax parse to guile.
Would be very glad if we could find a interface to expose this information that is sane and rigid manner. So we should discuss this feature. Anyway about the patch. I added a fluid that is setted with a closure that captures enough syntax information so that we can lookup the macro value local or global. It basically uses the same method as psyntax macroexpander. Now we can write, (define-syntax info (lambda (x) (syntax-case x () ((_ x) (pk (syntax-binding-info (syntax->datum #'x))) #'#f)))) and calling this in an example lead to (let-syntax ((a (lambda (x) #'#f))) (info a)) ;;; ((macro . #<procedure 1a68480 at ice-9/eval.scm:396:13 (a)>)) or (let ((a 1)) (info a)) ((lexical . #{a 310}#)) So with this I can attach meta information to macros local or not by using a weak hash. Anyway a hack but it shows what is needed. Happy Hacking :-) ---------- Forwarded message ---------- From: Stefan Israelsson Tampe <stefan.ita...@gmail.com> Date: Sun, Dec 4, 2011 at 8:22 PM Subject: syntax-local-value To: guile-devel <guile-devel@gnu.org> In looking at racket syntax-parse there seems to be some advanced macrology that is not included in guile. The light now is on the possibility to attach data to macros. I figure that I could reproduce this by using a weak hash-table but miss the functionality of syntax-local-value e.g. http://docs.racket-lang.org/reference/stxtrans.html#%28def._%28%28quote._~23~25kernel%29._syntax-local-value%29%29<http://docs.racket-lang.org/reference/stxtrans.html#%28def._%28%28quote._%7E23%7E25kernel%29._syntax-local-value%29%29> Basically the possibility to get the macro-object associated to a symbol in an environment if I have understyand this. So is there a guile feature that matches this at a reasonable level? Regards Stefan
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index 5ac01b8..619d761 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -386,6 +386,7 @@ If there is no handler at all, Guile prints an error and then exits." (define generate-temporaries #f) (define bound-identifier=? #f) (define free-identifier=? #f) +(define syntax-binding-info #f) ;; $sc-dispatch is an implementation detail of psyntax. It is used by ;; expanded macros, to dispatch an input against a set of patterns.
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. @@ -2398,10 +2406,14 @@ (lambda* (x #:optional (m 'e) (esew '(eval))) (expand-top-sequence (list x) null-env top-wrap #f m esew (cons 'hygiene (module-name (current-module)))))) + (set! syntax-binding-info + (lambda (x) + ((fluid-ref *macro-lookup*) x))) (set! identifier? (lambda (x) (nonsymbol-id? x))) + (set! datum->syntax (lambda (id datum)