From d9749ef854d266141b6414f56879ae765a35c4f5 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 15 Nov 2013 22:57:46 +0900 Subject: [PATCH] add for-each --- piclib/built-in.scm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 0a2fbca0..eb38a8ed 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -155,6 +155,23 @@ (single-map f list) (multiple-map f (cons list lists)))) +(define (for-each f list . lists) + (define (single-for-each f list) + (if (null? list) + #f + (begin + (f (car list)) + (single-for-each f (cdr list))))) + (define (multiple-for-each f lists) + (if (any null? lists) + #f + (begin + (apply f (map car lists)) + (multiple-for-each f (map cdr lists))))) + (if (null? lists) + (single-for-each f list) + (multiple-for-each f (cons list lists)))) + (define-macro (let bindings . body) (if (symbol? bindings) (begin