commit cc5dbe88949a5d8e4c10d9891d60e61b861181d2
parent 2ba02919ba8c74ef2b877358291162ef9f4432a3
Author: Ed van Bruggen <edvb@uw.edu>
Date: Tue, 26 Nov 2019 23:59:32 -0800
Error in lib if list given is an incorrect form
Diffstat:
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/tibs/lib.tsp b/tibs/lib.tsp
@@ -122,6 +122,7 @@
(define (count x lst)
(cond ((nil? lst) 0)
+ ((atom? lst) (error 'count "expected proper list"))
((= x (car lst)) (+ 1 (count x (cdr lst))))
(else (count x (cdr lst)))))
@@ -143,12 +144,14 @@
out)))
(define (append x y)
- (if x
- (cons (car x) (append (cdr x) y))
- y))
+ (cond
+ ((pair? x) (cons (car x) (append (cdr x) y)))
+ ((nil? x) y)
+ (else (error 'append "expected proper list"))))
(define (zip x y)
(cond ((and (nil? x) (nil? y)) nil)
+ ((or (nil? x) (nil? y)) (error 'zip "given lists of unequal length"))
((and (pair? x) (pair? y))
(cons (cons (car x) (car y))
(zip (cdr x) (cdr y))))))