week7a_sol

week7a_sol - CS61A Notes Week 07a (solutions): Applicative...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

week7a_sol - CS61A Notes Week 07a (solutions): Applicative...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online