Make this compile again

This commit is contained in:
Justin Ethier 2016-02-01 21:18:40 -05:00
parent e2a455ca3f
commit 745238c639

View file

@ -48,7 +48,7 @@
((begin? (car exp)) ((begin? (car exp))
(let* ((expr (car exp)) (let* ((expr (car exp))
(begin-exprs (begin->exps expr)) (begin-exprs (begin->exps expr))
(expanded-exprs (map (lambda (expr) (my-expand expr env)) begin-exprs))) (expanded-exprs (map (lambda (expr) (inner-expand expr env)) begin-exprs)))
(expand-body (expand-body
(append result (reverse expanded-exprs)) (append result (reverse expanded-exprs))
(cdr exp) (cdr exp)
@ -56,19 +56,18 @@
(else (else
(expand-body (expand-body
(cons (cons
(my-expand (car exp) env) (inner-expand (car exp) env)
result) result)
(cdr exp) (cdr exp)
env)))) env))))
(define (my-expand exp env) (define (my-expand exp env)
(inner-expand exp env #f)) (inner-expand exp env))
;; TODO: replace my-expand's below (and above in expand-body) with inner-expand. still trying to figure out how to use body? arg though.
;; TODO: need to be able to splice expanded begins somehow. ;; TODO: need to be able to splice expanded begins somehow.
;; maybe pass built up exp list to it and splice the begin into that before ;; maybe pass built up exp list to it and splice the begin into that before
;; continuing expansion ;; continuing expansion
(define (inner-expand exp env body?) (define (inner-expand exp env) ; body?)
(cond (cond
((const? exp) exp) ((const? exp) exp)
((prim? exp) exp) ((prim? exp) exp)
@ -84,15 +83,15 @@
; (lambda->exp exp)) ; (lambda->exp exp))
)) ))
((define? exp) (if (define-lambda? exp) ((define? exp) (if (define-lambda? exp)
(my-expand (define->lambda exp) env) (inner-expand (define->lambda exp) env)
`(define ,(my-expand (define->var exp) env) `(define ,(inner-expand (define->var exp) env)
,@(my-expand (define->exp exp) env)))) ,@(inner-expand (define->exp exp) env))))
((set!? exp) `(set! ,(my-expand (set!->var exp) env) ((set!? exp) `(set! ,(inner-expand (set!->var exp) env)
,(my-expand (set!->exp exp) env))) ,(inner-expand (set!->exp exp) env)))
((if? exp) `(if ,(my-expand (if->condition exp) env) ((if? exp) `(if ,(inner-expand (if->condition exp) env)
,(my-expand (if->then exp) env) ,(inner-expand (if->then exp) env)
,(if (if-else? exp) ,(if (if-else? exp)
(my-expand (if->else exp) env) (inner-expand (if->else exp) env)
;; Insert default value for missing else clause ;; Insert default value for missing else clause
;; FUTURE: append the empty (unprinted) value ;; FUTURE: append the empty (unprinted) value
;; instead of #f ;; instead of #f
@ -110,16 +109,16 @@
((symbol? (car exp)) ((symbol? (car exp))
(let ((val (env:lookup (car exp) env #f))) (let ((val (env:lookup (car exp) env #f)))
(if (tagged-list? 'macro val) (if (tagged-list? 'macro val)
(my-expand ; Could expand into another macro (inner-expand ; Could expand into another macro
(macro:expand exp val env) (macro:expand exp val env)
env) env)
(map (map
(lambda (expr) (my-expand expr env)) (lambda (expr) (inner-expand expr env))
exp)))) exp))))
(else (else
(map (map
(lambda (expr) (my-expand expr env)) (lambda (expr) (inner-expand expr env))
exp)))) exp))))
(else (else
(error "unknown exp: " exp)))) (error "unknown exp: " exp))))