Due by class time Thursday, November 14
Download the file assign15.scm and use it as your starting point for this assignment. This is the starting code that we used for class today, with support added for some of the primitives and infix operators from the last assignment. To use the auto-tester program for this assignment, download the files hw15-tester.scm and auto-tester-base.scm and put them in the same folder as assign15.scm. (If you've already downloaded auto-tester-base.scm before, you don't need to download it again.) Then uncomment the line (require "hw15-tester.scm") at the top of assign15.scm and type (test:) at the DrRacket prompt.
Add while-loops to your language, with the following syntax:
(while condition : body ...)
One or more body expressions may appear after the : symbol. To evaluate a while, the condition expression is first evaluated in the current environment. If the result is true, each body expression is evaluated in order, and then the cycle repeats, until condition becomes false, at which point the loop terminates and returns the symbol done as the final result. For example:
==> (with [x = 3] : (while (x > 0) : (print x) (x := (x - 1)))) 3 2 1 done ==> (with [n = 12] [steps = 0] : (while (n > 1) : (print n) (if ((n % 2) == 0) then (n := (n / 2)) else (n := ((3 * n) + 1))) (steps := (steps + 1))) (print n) (print "reached 1 after" steps "steps")) 12 6 3 10 5 16 8 4 2 1 reached 1 after 9 steps done
Submit your completed assign15.scm file using the Homework Upload Site. Make sure to include your name and the assignment number in a comment at the top of your file.
If you have questions about anything, don't hesitate to ask!