# notes06 - (zero(random 10 Because it’s not a function Why...

This preview shows page 1. Sign up to view the full content.

> (def (zero x) (- x x)) ; This function should always return 0. zero > (applic (zero (random 10))) (zero (random 10)) (random 10) ==> 5 (zero 5) ----> (- 5 5) ==> 0 0 ; Applicative order does return 0. > (normal (zero (random 10))) (zero (random 10)) ----> (- (random 10) (random 10)) (random 10) ==> 4 (random 10) ==> 8 (- 4 8) ==> -4 -4 ; Normal order doesn’t. The rule is that if you’re doing functional programming, you get the same answer regardless of order of evaluation. Why doesn’t this hold for
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (zero (random 10)) ? Because it’s not a function! Why not? EFciency: Try computing (square (square (+ 2 3))) in normal and applicative order. Applicative order is more eFcient because it only adds 2 to 3 once, not four times. (But later in the semester we’ll see that sometimes normal order is more eFcient.) Note that the reading for next week is section 1.3, skipping 1.2 for the time being. 272...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online