Comp 210
Due: At the beginning of class on 97.Jan.28 (Wed.)
;; fact: num -> num ;; Return n!, which stands for n*(n-1)*(n-2)*...*3*2*1 ;; (define fact (lambda (n) (if (zero? n) 1 (* n (fact (- n 1)))))) ;; multfib: num -> num ;; A multiplicative version of the fibonacci sequence. ;; (define multfib (lambda (n) (if (< n 3) n (* (multfib (- n 1)) (multfib (- n 2)))))) ;; threes: num -> num ;; Returns 1??? ;; (define threes (lambda (n) (if (< n 2) 1 (threes (if (even? n) (/ n 2) (+ 1 (* n 3)))))))(These functions also appear in the file
~comp210/Assignments/hw02-problem1.ss
.)
Evaluate each of these functions for values of n between 0 and 6 inclusive. For each value of n, use Donkey to determine the total number of calls made to each function. (The initial call counts, so the answer for n = 0 is 1 in each case.)
For a small amount of extra credit, estimate the number of recursive calls made by each function in terms of n. (Warning: I don't know the answer for threes.)
handle-lon
).
(cons key (cons datum null))
,
where
key
is a symbol
and
datum
is any Scheme value.
Define an Association List (i.e., a list of Associations).
Using the design recipe,
write the function lookup,
which takes a symbol and an Association List.
It searches the association list until it finds an association whose
key is the same as its first argument.
If it finds such an association, it returns the second element of
the association.
If not, it returns¹
#f
.
#f
?
Is there a way around the problem?
(back)