# notes01s - ,orderofevaluation[Solutionsv1.0...

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

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,

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

notes01s - ,orderofevaluation[Solutionsv1.0...

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

View Full Document
Ask a homework question - tutors are online