[plt-scheme] expand vs. local-expand; make-syntax-mapping

From: Doug Orleans (dougo at ccs.neu.edu)
Date: Wed Jul 16 17:05:46 EDT 2003

I'm still unclear about all the differences between `expand' and
`local-expand'.  Why doesn't `expand' allow a stop-list?  If the
stop-list is empty, should `local-expand' produce only primitive
syntax?  Here's some helpful macros:

(define-syntax (quote-expand stx)
  (syntax-case stx ()
    ((_ rest)
     #`'#,(expand #'rest))))
(define-syntax (quote-local-expand stx)
  (syntax-case stx ()
    ((_ rest)
     #`'#,(local-expand #'rest 'expression '()))))

This is starting to look like line-noise...  Anyway, these give
different results for unsyntax:

> (pretty-print (quote-expand #`#,foo))
(let-values (((arg)
              (#%app datum->syntax-object (quote-syntax here) (#%top . foo))))
  (let-values (((rslt) (#%app (lambda (e) e) arg)))
    (if rslt
      (let-values (((g11) rslt)) g11)
      (#%app raise-syntax-error (#%datum . #f) (#%datum . "bad syntax") arg))))
> (pretty-print (quote-local-expand #`#,foo))
(let-values (((arg)
              (#%app datum->syntax-object (quote-syntax here) (#%top . foo))))
  (let-values (((rslt) (#%app (lambda (e) e) arg)))
    (if rslt
      (let-values (((g12) rslt))
        (letrec-syntaxes+values (((uq3)
                                  (make-syntax-mapping 0 (quote-syntax g12))))
                                ()
          g12))
      (#%app raise-syntax-error (#%datum . #f) (#%datum . "bad syntax") arg))))

First, is there a deep reason for these to be different?  Second, is
`letrec-syntaxes+values' a primitive syntactic form?  If so, it should
be added to the grammar in section 12.6.1.  Third, what's the deal
with `make-syntax-mapping'?  Why is the numeric argument not wrapped
in #%datum?

--dougo at ccs.neu.edu


Posted on the users mailing list.