Thu Apr 30 14:34:45 CEST 2009

sometimes it doesn't expand

This won't expand ns forms unless there is a (require (for-syntax
"ns.ss")) in the definition place of this macro  Expansion happens in
the transformer environment, so it needs bindings for the forms.

;; Collects all syntax definitions.
(define-syntax (define-signature-begin stx)
  (define (tx-forms forms)
    (for/list ((form (in-stx forms)))
      (if (identifier? form)
          (let ((top-form (expand-syntax-to-top-form form)))
            ;; (pretty-print (syntax->datum top-form))
            (syntax-case top-form ()
              ((form names expr)
               (and (eq? 'define-syntaxes (syntax->datum #'form)))
               #`(define-syntaxes names expr)))))))
  (syntax-case stx (extends)
    ((_ id^ . forms)
     #`(define-signature id^
         #,(tx-forms #'forms)))
    ((_ id^ extends id-super^ . forms)
     #`(define-signature id^ extends id-super^
         #,(tx-forms #'forms)))))