[plt-scheme] macro-generating macros and the bizarre properties of syntax-local-get-shadower

From: Dimitris Vyzovitis (vyzo at media.mit.edu)
Date: Mon May 14 11:13:24 EDT 2007

Can someone explain this:
(module bar mzscheme
  (begin-for-syntax
    (define (make-foos)
      (let ((lst (generate-temporaries (list 'foo 'foocheck 'foov))))
        (printf "temps:~a~n" (map syntax-object->datum lst))
        lst)))

  (define-syntax (define-foo1 stx)
    (syntax-case stx ()
      ((_ val)
       (let-values (((foo foocheck foov) (apply values (make-foos))))
         (syntax-local-introduce
          #`(begin (define-syntax #,foo val)
                   (define-syntax (#,foocheck stx)
                     (let ((#,foov (syntax-local-value (quote-syntax #,foo))))
                       (quasisyntax #,#,foov)))
                   (provide #,foo #,foocheck)))))))

  (define-syntax (define-foo2 stx)
    (syntax-case stx ()
      ((_ val)
       (let-values
           (((foo foocheck foov)
             (apply values (map syntax-local-get-shadower (make-foos)))))
         (syntax-local-introduce
          #`(begin (define-syntax #,foo val)
                   (define-syntax (#,foocheck stx)
                     (let ((#,foov (syntax-local-value (quote-syntax #,foo))))
                       (quasisyntax #,#,foov)))
                   (provide #,foo #,foocheck)))))))
  (define-foo1 1)
  (define-foo2 2)
  )

temps:(foo1 foocheck2 foov3)
temps:(foo4 foocheck5 foov6)
> (require bar)
> (foocheck2)
compile: bad syntax; literal data is not allowed, because no #%datum
syntax transformer is bound in: 1
> (foocheck5)
2
> (version)
"369.100"

-- vyzo



Posted on the users mailing list.