notes01s -...

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

View Full Document Right Arrow Icon
CS61A Notes 01 – Scheme basics, order of evaluation [Solutions v1.0] 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?  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 1.  Therefore, 
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

notes01s -...

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