fix for-each.

This commit is contained in:
Jan Nieuwenhuizen 2016-07-24 12:40:44 +02:00
parent 07a5f716fc
commit 8c1a5f19da
3 changed files with 6 additions and 5 deletions

2
mes.c
View file

@ -342,8 +342,6 @@ eval (scm *e, scm *a)
#if DEBUG
printf ("\neval e=");
display (e);
printf ("\na=");
display (a);
puts ("");
#endif
scm *macro;

View file

@ -158,8 +158,10 @@
(define (identity x) x)
(define (for-each f l . r)
(apply map (cons f (cons l r)))
*unspecified*)
(cond ((null? l) '())
((null? r) (f (car l)) (for-each f (cdr l)))
((null? (cdr r))
(for-each f (cdr l) (cdar r)))))
(define (not x)
(cond (x #f)

View file

@ -95,6 +95,7 @@
(pass-if "map" (sequal? (map identity '(1 2 3 4)) '(1 2 3 4)))
(pass-if "map 2 " (sequal? (map (lambda (i a) (cons i a)) '(1 2 3 4) '(a b c d))
'((1 . a) (2 . b) (3 . c) (4 . d))))
(pass-if "for-each" (sequal? (let ((acc '())) (for-each (lambda (x) (set! acc (cons x acc))) '(1 2 3 4)) acc) '(4 3 2 1)))
(define xxxa 0)
(pass-if "set! " (seq? (begin (set! xxxa 1) xxxa) 1))
(pass-if "set! 2" (seq? (let ((a 0)) (set! a 1) a) 1))