Due by class time Thursday, October 10
Review today's code examples from class.
Download the file assign9.scm and use it as your starting point for this assignment (this is our interpreter from class today).
Add a new primitive function to the interpreter's initial environment called (cube n), which computes the cube of its argument. Examples:
(meaning '(cube 3) ) → 27 (meaning '(cube (1 + 2)) ) → 27 (meaning '(cube (square b)) ) → 64
Currently, application expressions must be of the form (<var> <exp>), that is, the application operator <var> must be a symbol like square, minus, etc. Modify the interpreter so that the application operator can be any expression in our language, as shown in the examples below:
(meaning '((if True then square else squareroot) 4) ) → 16 (meaning '((if False then square else squareroot) 4) ) → 2 (meaning '((if ((1 + 1) == 2) then ! else square) (2 + 3)) ) → 120 (meaning '((if False then ! else (if ((1 + 1) == 3) then ! else square)) 5) ) → 25
Add support to the interpreter for application expressions of the form (<var> <exp> <exp>) containing two operands. Also add a new primitive function called (average x y) to the initial environment, which takes two input values and computes their average. Hint: you will need to add a new 2-argument lambda function to the initial environment, bound to the symbol average. For example:
(meaning '(average 3 5) ) → 4 (meaning '(average a c) ) → 2 (meaning '(average (a + b) (c + 4)) ) → 5
Submit your modified assign9.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!