Created
May 20, 2012 00:17
-
-
Save leque/2732942 to your computer and use it in GitHub Desktop.
patch for Gauche/src/liblist.scm every
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/liblist.scm b/src/liblist.scm | |
index 0f470a8..d67ef95 100644 | |
--- a/src/liblist.scm | |
+++ b/src/liblist.scm | |
@@ -352,11 +352,16 @@ | |
(cond [(null-list? tail) (pred head)] ; tail call | |
[(not (pred head)) #f] | |
[else (loop (car tail) (cdr tail))]))) | |
- (let loop ([liss (cons lis more)]) | |
- (receive (cars cdrs) ((with-module gauche.internal %zip-nary-args) liss) | |
- (cond [(not cars)] | |
- [(not (apply pred cars)) #f] | |
- [else (loop cdrs)]))))) | |
+ (receive (heads tails) | |
+ ((with-module gauche.internal %zip-nary-args) (cons lis more)) | |
+ (or (not heads) | |
+ (let loop ([heads heads] [tails tails]) | |
+ (receive (next-heads next-tails) | |
+ ((with-module gauche.internal %zip-nary-args) tails) | |
+ (if next-heads | |
+ (and (apply pred heads) | |
+ (loop next-heads next-tails)) | |
+ (apply pred heads)))))))) | |
(define (filter pred lis) | |
(let loop ([lis lis] [r '()]) | |
diff --git a/test/list.scm b/test/list.scm | |
index 4a2e603..0fa0c60 100644 | |
--- a/test/list.scm | |
+++ b/test/list.scm | |
@@ -167,6 +167,44 @@ | |
(test* "delete-duplicates!" '("A" "b" "c" "d" "e") | |
(delete-duplicates! '("A" "b" "a" "B" "c" "d" "a" "e") string-ci=?)) | |
+(test* "any" #f (any even? '())) | |
+ | |
+(test* "any" #f (any even? '(1 3))) | |
+ | |
+(test* "any" #t (any even? '(1 2))) | |
+ | |
+(test* "any" 1 (any string->number '("1" "a"))) | |
+ | |
+(test* "any" 1 (any string->number '("1" "2"))) | |
+ | |
+(test* "any" 1 | |
+ (any string->number '("1" "2") '(10 10))) | |
+ | |
+(test* "any" 1 | |
+ (any string->number '("1" "2") '(10))) | |
+ | |
+(test* "any" #f | |
+ (any string->number '("1" "2") '())) | |
+ | |
+(test* "every" #t (every odd? '())) | |
+ | |
+(test* "every" #t (every odd? '(1 3))) | |
+ | |
+(test* "every" #f (every odd? '(1 2))) | |
+ | |
+(test* "every" #f (every string->number '("1" "a"))) | |
+ | |
+(test* "every" 2 (every string->number '("1" "2"))) | |
+ | |
+(test* "every" 2 | |
+ (every string->number '("1" "2") '(10 10))) | |
+ | |
+(test* "every" 1 | |
+ (every string->number '("1" "2") '(10))) | |
+ | |
+(test* "every" #t | |
+ (every string->number '("1" "2") '())) | |
+ | |
;;-------------------------------------------------------------------------- | |
(test-section "take and drop") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment