Skip to content
This repository has been archived by the owner on Jan 28, 2018. It is now read-only.

Commit

Permalink
EVALmacro
Browse files Browse the repository at this point in the history
  • Loading branch information
zaoqi committed Oct 21, 2017
1 parent 466c871 commit 0cfebdd
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions zscm.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -634,36 +634,16 @@
(define ms (make-hash))
(define (EVALmacro x)
(let ([x (macroexpand x)])
(cond
[(pair? x) (APPLYmacro (car x) (cdr x))]
[else x])))
(if (pair? x)
(cons (EVALmacro (car x)) (EVALmacro (cdr x)))
x)))
(define (macroexpand x)
(cond
[(and (pair? x) (eq? (car x) 'defmacro))
(hash-set! ms (second x) (evalp (third x)))
'(void)]
[(and (pair? x) (hash-ref ms (car x) #f)) => (λ (mf) (macroexpand (apply mf (cdr x))))]
[else x]))
(define (APPLYmacro f xs)
(cond
[(eq? f 'lambda) `(lambda ,(car xs) ,(BEGINmacro (cdr xs)))]
[(eq? f 'begin) (BEGINmacro xs)]
[(eq? f 'define) (error "APPLYmacro: define" f xs)]
[(eq? f 'quote) (if (null? (cdr xs)) (list 'quote (car xs)) (error "APPLYmacro: quote" f xs))]
[else (cons (EVALmacro f) (map EVALmacro xs))]))
(define (BEGINmacro xs)
(if (null? (cdr xs))
(EVALmacro (car xs))
(cons
'begin
(map
(λ (x)
(if (and (pair? x) (eq? (car x) 'define))
(if (null? (cdddr x))
`(define ,(cadr x) ,(EVALmacro (caddr x)))
(error "BEGINmacro: define" xs))
(EVALmacro x)))
xs))))
(define pre
'((defmacro gensymmacro
(λ xs
Expand Down

0 comments on commit 0cfebdd

Please sign in to comment.