mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
signal error on improper lists passed to map/for-each
This commit is contained in:
parent
9710962cd2
commit
18d0adf13b
1 changed files with 11 additions and 3 deletions
|
@ -60,19 +60,27 @@
|
|||
(define (map1 proc ls res)
|
||||
(if (pair? ls)
|
||||
(map1 proc (cdr ls) (cons (proc (car ls)) res))
|
||||
(reverse res)))
|
||||
(if (null? ls)
|
||||
(reverse res)
|
||||
(error "map: improper list" ls))))
|
||||
(define (mapn proc lol res)
|
||||
(if (every pair? lol)
|
||||
(mapn proc
|
||||
(map1 cdr lol '())
|
||||
(cons (apply proc (map1 car lol '())) res))
|
||||
(reverse res)))
|
||||
(if (every (lambda (x) (if (null? x) #t (pair? x))) lol)
|
||||
(reverse res)
|
||||
(error "map: improper list" ls))))
|
||||
(if (null? lol)
|
||||
(map1 proc ls '())
|
||||
(mapn proc (cons ls lol) '())))
|
||||
|
||||
(define (for-each f ls . lol)
|
||||
(define (for1 f ls) (if (pair? ls) (begin (f (car ls)) (for1 f (cdr ls)))))
|
||||
(define (for1 f ls)
|
||||
(if (pair? ls)
|
||||
(begin (f (car ls)) (for1 f (cdr ls)))
|
||||
(if (not (null? ls))
|
||||
(error "for-each: improper list" ls))))
|
||||
(if (null? lol) (for1 f ls) (begin (apply map f ls lol) (if #f #f))))
|
||||
|
||||
(define (any pred ls . lol)
|
||||
|
|
Loading…
Add table
Reference in a new issue