(define-datatype continuation continuation? (halt-cont) (proc-cont (cont continuation?)) (let-cont (syms (list-of symbol?)) (bodies (list-of expression?)) (env anything?) (cont continuation?)) (eval-bodies-cont (exps (list-of expression?)) (cont continuation?) (env anything?)) (change-cont (sym symbol?) (env anything?) (cont continuation?)) (cons-cont (v anything?) (cont continuation?)) (for-init-cont (test-exp expression?) (update-exps (list-of expression?)) (body expression?) (env anything?) (cont continuation?)) (for-test-cont (test-exp expression?) (update-exps (list-of expression?)) (body expression?) (env anything?) (cont continuation?)) (for-update-cont (test-exp expression?) (update-exps (list-of expression?)) (body expression?) (env anything?) (cont continuation?)) (or-cont (exps (list-of expression?)) (env anything?) (cont continuation?)) (eval-exps-cont (ls list?) (cont continuation?) (env anything?)) (if-cont (true-exp expression?) (false-exp expression?) (cont continuation?) (env list?))) (define apply-cont (lambda (cont val) (cases continuation cont [halt-cont () val] [change-cont (sym env cont) (apply-cont cont (change-env env sym val))] [proc-cont (cont) (apply-primitive-procedure (cadar val) (cdr val) cont)] [let-cont (syms bodies env cont) (eval-bodies bodies cont (extend-env syms val env))] [cons-cont (v cont) (apply-cont cont (cons v val))] [eval-bodies-cont (exps cont env) (eval-bodies exps cont env)] [eval-exps-cont (ls cont env) (eval-expressions-cps ls (cons-cont val cont) env)] [for-init-cont (test-exp update-exps body env cont) ;;; what to do with val??? nothing?!!! (eval-expression test-exp (for-test-cont test-exp update-exps body env cont) env)] [for-test-cont (test-exp update-exps body env cont) (if val (eval-expression body (for-update-cont test-exp update-exps body env cont) env) (apply-cont cont val))] [for-update-cont (test-exp update-exps body env cont) (eval-expressions-cps update-exps (for-init-cont test-exp update-exps body env cont) env)] [or-cont (exps env cont) (if val (apply-cont cont val) (eval-expression (or-exp exps) cont env))] [if-cont (true-exp false-exp cont env) (if val (eval-expression true-exp cont env) (eval-expression false-exp cont env))])))