* Added vararg case for for-each.

This commit is contained in:
Abdulaziz Ghuloum 2007-09-09 23:50:55 -04:00
parent 2692897900
commit 375b738ccb
3 changed files with 23 additions and 3 deletions

Binary file not shown.

View File

@ -536,7 +536,27 @@
(void)
(error who "length mismatch"))]
[else (error who "not a list")])]
[_ (error who "vararg not supported yet")])))
[(f ls . ls*)
(unless (procedure? f)
(error 'for-each "~s is not a procedure" f))
(unless (list? ls)
(error 'for-each "~s is not a list" ls))
(let ([n (length ls)])
(for-each
(lambda (x)
(unless (and (list? x) (= (length x) n))
(error 'for-each "~s is not a list" x)))
ls*)
(let loop ([n (length ls)] [ls ls] [ls* ls*])
(cond
[($fx= n 0)
(unless (and (null? ls) (andmap null? ls*))
(error 'for-each "list modified by ~s" f))]
[else
(unless (and (pair? ls) (andmap pair? ls*))
(error 'for-each "list modified by ~s" f))
(apply f (car ls) (map car ls*))
(loop (fx- n 1) (cdr ls) (map cdr ls*))])))])))
(module (andmap)
(define who 'andmap)

View File

@ -151,7 +151,7 @@
[expt C ba se]
[finite? S ba]
[floor C ba se]
[for-each S ba se]
[for-each C ba se]
[gcd C ba se]
[imag-part D ba se]
[inexact C ba]
@ -503,7 +503,7 @@
[assp S ls]
[assq C ls se]
[assv C ls se]
[cons* S ls]
[cons* C ls]
[filter S ls]
[find S ls]
[fold-left S ls]