-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path06-4-lasns.rkt
More file actions
executable file
·39 lines (33 loc) · 874 Bytes
/
06-4-lasns.rkt
File metadata and controls
executable file
·39 lines (33 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
;; A ListOfAlternatingNumbersAndStrings (LANS) is one of:
;; -- empty
;; -- (cons Number LASN)
;; A ListOfAlternatingStringsAndNumbers (LASN) is one of:
;; -- empty
;; -- (cons String LANS)
;; lans-fn : LANS -> ??
;; (define (lans-fn lans)
;; (cond
;; [(empty? lans) ...]
;; [else (...
;; (first lans)
;; (lasn-fn (rest lans)))]))
;; lasn-fn : LASN -> ??
;; (define (lasn-fn lasn)
;; (cond
;; [(empty? lasn) ...]
;; [else (...
;; (first lasn)
;; (lans-fn (rest lasn)))]))
;; strategy: Use template for LANS/LASN on lans
;; lans-sum : LANS -> Number
(define (lans-sum lans)
(cond
[(empty? lans) 0]
[else (+
(first lans)
(lasn-sum (rest lans)))]))
;; lasn-sum : LASN -> Number
(define (lasn-sum lasn)
(cond
[(empty? lasn) 0]
[else (lans-sum (rest lasn))]))