1 (define (list-ref items n)
4 (list-ref (cdr items) (- n 1))))
7 (define (length-ter a count)
10 (length-iter (cdr a) (+ 1 count))))
11 (length-iter items 0))
13 (define (append list1 list2)
17 (append (cdr list1) list2))))
20 (cond ((null? l) (error "Empty List"))
22 (else (last-pair (cdr l)))))
24 (define (test-case actual expected)
27 (format #t "Actual: ~A Expected: ~A" actual expected))
36 (define us-coins (list 50 25 10 5 1))
37 (define uk-coins (list 100 50 20 10 5 2 1 0.5))
39 (define (cc amount coin-values)
40 (cond ((= amount 0) 1)
41 ((or (< amount 0) (no-more? coin-values)) 0)
44 (except-first-denomination coin-values))
46 (first-denomination coin-values))
49 ;; Define the procedures first-denomination, except-first-denomination, and no-more? in terms of primitive operations on list structures. Does the order of the list coin-values affect the answer produced by cc? Why or why not?
51 (define first-denomination car)
52 (define except-first-denomination cdr)
53 (define no-more? null?)
55 ;; no, order of coin-values shouldn't matter because it doesn't matter in reali life
57 (test-case (cc 100 us-coins) 292)