week7a_sol

# week7a_sol - CS61A Notes Week 07a(solutions Applicative and...

This preview shows pages 1–2. Sign up to view the full content.

CS61A Notes – Week 07a (solutions): Applicative and Normal Order, Lazy evaluator, Nondeterministic evaluator Applicative vs. Normal Order QUESTIONS 1. Above, applicative order was more efficient. Define a procedure where normal order is more efficient. Anything where not evaluating the arguments will save time works. Most trivially, (define (f x) 3) ;; a function that always returns 3 When you call (f (fib 10000)), applicative order would choke, but normal order would just happily drop (fib 10000) and just return 3. 2. Evaluate this expression using both applicative and normal order: (square (random x)) . Will you get the same result from both? Why or why not? Unless you’re lucky, the result will be quite different. Expanding to normal order, you have (* (random x) (random x)), and the two separate calls to random will probably return different values. 3. Consider a magical function count that takes in no arguments, and each time it is invoked, it returns 1 more than it did before, starting with

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

week7a_sol - CS61A Notes Week 07a(solutions Applicative and...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online