It is vain to do with more what can be done with fewer.- William of Occam, 14th century
The lyf so short, the craft so long to lerne.- ChaucerExperience helps you recognize a mistake
when you make it again.- Dorothy Parker
(define (foo n) (cond ((= n 0) 1) ((= n 1) 2) ((= n 2) 5) (else (+ (foo (- n 1)) (foo (- n 3))))))Fill in the five missing elements in the right hand column. (2 points each)
n | (foo n) |
---|---|
0 | 1 |
1 | |
2 | 5 |
3 | |
4 | |
5 | |
6 |
For instance
(everynum (lambda (x) (* x x)) '(2 for the show 3 to get ready 4 to go))
evaluates to (4 for the show 9 to get ready 16 to go).
everynum can be defined using higher order functions:
(define (everynum f sen) (every (lambda (x) (if (number? x) (f x) x)) sen))Define everynum using recursion instead. (10 points)
(sentence (sentence 'um 'diddle 'diddle 'diddle 'um 'diddle 'ay) (sentence 'um 'diddle 'diddle 'diddle 'um 'diddle 'ay) (word (word 'super 'cali 'fragilistic 'expialidocious) '!) (sentence 'even 'though 'the 'sound 'of 'it 'is 'something 'quite 'atrocious) (word (word 'super 'cali 'fragilistic 'expialidocious) '!) (sentence 'um 'diddle 'diddle 'diddle 'um 'diddle 'ay) (sentence 'um 'diddle 'diddle 'diddle 'um 'diddle 'ay) 'shes (word (word 'super 'cali 'fragilistic 'expialidocious) '!) (word 'super 'cali 'fragilistic 'expialidocious) (word 'super 'cali 'fragilistic 'expialidocious) (word (word 'super 'cali 'fragilistic 'expialidocious) '!))
(define (a f g) (lambda (h x) (f h (g h x)))) (define (b f g) (lambda (h x) (f (lambda (y) (g h y)) x))) (define (n0 f x) x) (define (n1 f x) (f x)) (define n2 (a n1 n1)) (define n3 (a n1 n2))what does
(* 2 ((b n3 (a n2 (b (b n3 (a (b n2 n2) n3)) (a n2 n3)))) (lambda (x) (+ x 1)) 12))return, and why? (5 points)