From 5680368dd6345def423482af5c25ec3c7894c9bf Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Thu, 11 Apr 2013 16:20:52 -0400 Subject: Added do-while --- hw08.scm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hw08.scm b/hw08.scm index db673c7..3252a28 100644 --- a/hw08.scm +++ b/hw08.scm @@ -58,6 +58,8 @@ while-stmt) (statement ("var" (separated-list identifier ",") ";" statement) block-stmt) + (statement ("do" statement "while" expression) + do-while-stmt) ; (3.1) expressions (expression (number) lit-expr) @@ -228,6 +230,14 @@ (block-stmt (ids statement) (execute-statement statement (extend-env ids (map (lambda (id) 0) ids) env) )) + + (do-while-stmt (stmt exp) + (let loop () + (begin + (execute-statement stmt env) + (if (true-value? (eval-expression exp env)) + (loop) + '())))) ))) ; expression evaluator @@ -416,4 +426,7 @@ ;(scan&parse test3.9a) ;(scan&parse test3.9b) (scan&parse&eval test3.9a) -(scan&parse&eval test3.9b) \ No newline at end of file +(scan&parse&eval test3.9b) + +; this will let us enter the repl immediately +(read-eval-print) \ No newline at end of file -- cgit v1.2.3