Skip to content

Commit

Permalink
29.scm
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jul 26, 2014
1 parent 181d8d3 commit bcfd3b0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ch6/29.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;; Consider this variant of cps-of-exps
(load-relative "../libs/init.scm")
(load-relative "./base/test.scm")
(load-relative "./base/cps.scm")
(load-relative "./base/data-structures.scm")
(load-relative "./base/cps-cases.scm")
(load-relative "./base/cps-lang.scm")
(load-relative "./base/base-iterp.scm")

;; This version of cps-of-exps is continuation passing style,
;; like the optimized version fact, acc used as cont.

(define cps-of-exps
(lambda (exps builder)
(let cps-of-rest ((exps exps) (acc '()))
;; cps-of-rest : Listof(InpExp) × Listof(SimpleExp) → TfExp
(cond
((null? exps) (builder (reverse acc)))
((inp-exp-simple? (car exps))
(cps-of-rest (cdr exps)
(cons
(cps-of-simple-exp (car exps))
acc)))
(else
(let ((var (fresh-identifier 'var)))
(cps-of-exp (car exps)
(cps-proc-exp
(list var)
(cps-of-rest
(cdr exps)
(cons (cps-of-simple-exp (var-exp var)) acc))))))))))

(run-all)

0 comments on commit bcfd3b0

Please sign in to comment.