Comp210
Due: 97.Feb.04 (Wed.) in class
These exercises should be done on Owlnet using Donkey and Scheme.
DrScheme and Donkey evaluate the expressions Ei in left to right order, E1, E2, ..., En. Your task is to step through the evaluation of the following expressions using the reduction rules described in class (and used by Donkey). However, you should reverse the order of evaluation for the law of function application. You should evaluate the expressions Ei in the right to left order, En, ..., E2, E1. Your answers should resemble the sequence of expressions produced by Donkey during stepping.
(+ (* (+ 2 4) (+ 3 -4)) (+ (+ 4 7) (- 6 7)))
(if (> 3 4) (/ 4 0) (if #t (+ 8 9) (/ 22 2)))
(define fib (lambda (n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2)))))) (fib 3)
(remove-duplicates (list 'a 'b 'c 'a)) = (list 'a 'b 'c)
.
(the exact order of the result isn't important).
As always, follow the program-design recipe from class.
Hint: First write a helper function
;; remove: symbol, list-of-symbols --> list-of-symbols ;; (remove victim los) returns a list like los, ;; but with all occurrences of victim are removed. ;;
expt
.
However, you may use the multiplication (*
) operation.
posn
into Dr.Scheme,
find the "Languages" menu and select "Select Library...",
and request the library
~comp210/lib/teach/pingp-lib.ss
.
(The name pingp-lib.ss
should appear next to the
Check Syntax button,
indicating success.)
posn+
and posn*
.
mover
.
define-struct
to make a ball
structure.
Of the four indicated direction and speed functions,
write one of {ns-direction,ew-direction},
and write one of {ns-speed, ew-speed}.
One test case per function is sufficient.
You don't need to provide a description of these four functions
(their names are self-explanatory),
but you do still need
to provide the contract, e.g. ns-speed: ball --> posn
.
move
.
tracer
and trace-ball
as indicated.
For further fun: You can develop and run examples as discussed in the book about drawing shapes, playing hangman, and playing a complete pingpong game.