Refactoring

This commit is contained in:
Justin Ethier 2016-04-30 02:50:48 -04:00
parent 6ed5d735f6
commit ce801e092a

View file

@ -903,19 +903,18 @@
(append begin-exprs (cdr exp)) (append begin-exprs (cdr exp))
env))) env)))
((app? this-exp) ((app? this-exp)
(let ((macro #f)) (cond
(when (and (app? this-exp) ((symbol? (caar exp))
(symbol? (caar exp))) (let ((val (env:lookup (caar exp) env #f)))
(set! macro (env:lookup (caar exp) env #f))) (if (tagged-list? 'macro val)
(if (tagged-list? 'macro macro)
;; Expand macro here so we can catch begins in the expanded code, ;; Expand macro here so we can catch begins in the expanded code,
;; including nested begins ;; including nested begins
(let ((expanded (macro:expand this-exp macro env))) (expand-body
;; Call with expanded macro in case we need to expand again result
(expand-body (cons
result (macro:expand this-exp val env)
(cons expanded (cdr exp)) (cdr exp))
env)) env)
;; No macro, use main expand function to process ;; No macro, use main expand function to process
(expand-body (expand-body
(cons (cons
@ -925,6 +924,15 @@
result) result)
(cdr exp) (cdr exp)
env)))) env))))
(else
(expand-body
(cons
(map
(lambda (expr) (expand expr env))
this-exp)
result)
(cdr exp)
env))))
(else (else
(error "unknown exp: " this-exp)))))) (error "unknown exp: " this-exp))))))