[gambit-list] Intermixing syntax-rules and define-macro

Bradley Lucier lucier at math.purdue.edu
Thu Sep 27 18:42:36 EDT 2012


Here is an example from

http://c2.com/cgi/wiki?DefineSyntax

;; Common-lisp-style define-macro, implemented on top of syntax-case.
  ;;
  ;; Note that this is a macro that generates another macro (with the
  ;; appropriate name).
  ;;
  ;; This is the weirdest one.  It...
  ;;  * strips all syntax information out of the incoming s-exp,
  ;;    leaving raw symbols.
  ;;  * runs the result through the transformer function
  ;;  * injects that result back into the original scope
  ;;  * returns the final result for processing
  ;;
  ;; Note that because we're generating the *entire* result through
  ;; DATUM->SYNTAX-OBJECT, we don't need to quote or expand anything
  ;; with SYNTAX.
  (define-syntax define-macro
    (lambda (stx)
      (syntax-case
       stx ()
       ((_ (macro . args) . body)
        (syntax (define-macro macro (lambda args . body))))
       ((_ macro transformer)
        (syntax (define-syntax (macro stx2)
                  (let ((v (syntax-object->datum stx2)))
                    (datum->syntax-object stx2
                                          (apply transformer (cdr v))))))))))

Maybe you could use this to redefine Gambit's define-macro.

HTH.

Brad


More information about the Gambit-list mailing list