unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* syntax-local-value patch for discussion
@ 2011-12-05 18:12 Stefan Israelsson Tampe
  2011-12-08 21:58 ` Ian Price
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Stefan Israelsson Tampe @ 2011-12-05 18:12 UTC (permalink / raw)
  To: guile-devel


[-- Attachment #1.1: Type: text/plain, Size: 1983 bytes --]

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.itampe@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

[-- Attachment #1.2: Type: text/html, Size: 2493 bytes --]

[-- Attachment #2: boot-9-local-binding.diff --]
[-- Type: text/x-patch, Size: 515 bytes --]

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.

[-- Attachment #3: psyntax-local-binding.diff --]
[-- Type: text/x-patch, Size: 1720 bytes --]

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)

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-01-26 15:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).