;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; begin-syntax.scm - Inline macro operations. ;;; ;;; Copyright (c) 2016, Evan Hanson ;;; See LICENSE for details. ;;; (declare (module begin-syntax) (export begin-syntax) (import-for-syntax lolevel matchable)) ;; ;; Evaluates its body and immediately inserts the final result into the ;; program, as though by macro expansion. ;; ;; If the result is a macro transformer, then this is immediately ;; invoked with no arguments and the result is inserted into the ;; program. *Note that in this case the final expression of the ;; `begin-syntax` body will be evaluated twice*. ;; ;; This form can be thought of as a macro definition followed by its ;; immediate expansion. For example: ;; ;; (begin-syntax '(+ 1 2)) ;; ;; ; => (let-syntax ((a (er-macro-transformer ;; (lambda (_ _ _) '(+ 1 2))))) ;; (a)) ;; (define-syntax begin-syntax (ir-macro-transformer (lambda (e i c) (let ((name (gensym "transformer"))) (match e ((_ exp0 ... expn) (let ((_ (for-each eval exp0)) (v (eval expn))) (cond ((record-instance? v 'transformer) `(let-syntax ((,name ,expn)) (,name))) (else v)))))))))