I see that the following evaluates successfully:

;;; this-file.sls --

(import (rnrs) (srfi lightweight-testing))
(check-set-mode! 'report-failed)

(check
 (let ()
   (define-syntax doit
     (lambda (macro-use-stx)
       (syntax-case macro-use-stx ()
         ((use)
          (datum->syntax (syntax use) '(a))))))
   (let ((a (lambda () 123)))
     (doit)))
 => 123)

(check
 (let ()
   (define-syntax doit
     (lambda (macro-use-stx)
       (syntax-case macro-use-stx ()
         ((use)
          (datum->syntax (syntax use)
                         '(list (a) (b) (c)))))))
   (let ((a (lambda () 123)))
     (let ((b (lambda () 456)))
       (let ((c (lambda () 789)))
         (doit)))))
 => '(123 456 789))

(check
 (let ()
   (define-syntax doit
     (lambda (macro-use-stx)
       (syntax-case macro-use-stx (alpha)
         ((use ?arg)
          (datum->syntax (syntax ?arg) '(a))))))
   (let ((a (lambda () 123)))
     (doit alpha)))
 => 123)

(check-report)

;;; end of file

So it seems that macros at 'expand' time have access
to all the bindings that will be available at 'run'
time in the region of a macro use.  Informations about
those bindings is stored somehow in MACRO-USE-STX.

But why the context that DATUM->SYNTAX needs to query
the available bindings has to be '(syntax use)' or
'(syntax ?arg)' when ?ARG is a literal and not
MACRO-USE-STX itself?  And why the context is not
implicit, as if the <syntax-case clause>s are evaluated
in a:

  (parameterize ((macro-use-context MACRO-USE-STX))
     ---)

form?

The pattern is used only for matching, it does not
introduce new bindings, so the bindings that
DATUM->SYNTAX has available to build the result
should be fixed once MACRO-USE-STX has been built.
Or not?

Reply via email to