From 6b742a7fa3307f4853794b36eb94ce05f92a9d82 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 14 Nov 2013 22:48:06 +0900 Subject: [PATCH] using any instead of every in map function may make the run a bit faster --- piclib/built-in.scm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 216c7b0d..9f524fa6 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -138,6 +138,18 @@ (every pred (cdr list)) #f))) +(define (null? obj) + (null? obj)) + +(define (any pred list) + (if (null? list) + #f + ((lambda (it) + (if it + it + (any pred (cdr list)))) + (pred (car list))))) + (define (map f list . lists) (define (single-map f list) (if (null? list) @@ -145,10 +157,10 @@ (cons (f (car list)) (map f (cdr list))))) (define (multiple-map f lists) - (if (every pair? lists) + (if (any null? lists) + '() (cons (apply f (single-map car lists)) - (multiple-map f (single-map cdr lists))) - '())) + (multiple-map f (single-map cdr lists))))) (if (null? lists) (single-map f list) (multiple-map f (cons list lists))))