MIT Scheme中macroexpand-1和macroexpand如何做?

How to do macroexpand-1 and macroexpand in MIT Scheme?

在 Common Lisp 中,我可以定义一个两级宏并像这样扩展宏:

(defmacro calc (a op b)
  (list op a b))

(defmacro twice (x)
  (list 'calc x '+ x))

(twice 10)
(macroexpand-1 '(twice 10))
(macroexpand '(twice 10))

输出:

20
(CALC 10 + 10)
(+ 10 10)

现在我正尝试在 MIT Scheme 中做同样的事情:

(define-syntax calc
  (syntax-rules ()
    ((_ a op b)
     (op a b))))

(define-syntax twice
  (syntax-rules ()
    ((_ x)
     (calc x + x))))

(twice 10)

我怎样才能在 MIT Scheme 中做相当于 macroexpand-1macroexpand 的事情?

在 Racket 中,macroexpand 将是

(syntax->datum
  (expand-to-top-form '(twice 10)))
;; '(+ 10 10)

macroexpand-1将是

(syntax->datum (expand-once '(twice 10)))
;; '(calc 10 + 10)

M. Felleisen 的 scheme 中有宏调试的论文。 参见 here