diff --git a/scheme/srfi/srfi-1.scm b/scheme/srfi/srfi-1.scm index 10d2ee5..1fac7a1 100644 --- a/scheme/srfi/srfi-1.scm +++ b/scheme/srfi/srfi-1.scm @@ -1027,6 +1027,26 @@ ;;; We extend MAP to handle arguments of unequal length. (define map map-in-order) +;;; Apply F across lists, guaranteeing to go left-to-right. +;;; NOTE: Some implementations of R5RS MAP are compliant with this spec; +;;; in which case this procedure may simply be defined as a synonym for FOR-EACH. + +(define (for-each f lis1 . lists) + (check-arg procedure? f for-each) + (if (pair? lists) + (let recur ((lists (cons lis1 lists))) + (receive (cars cdrs) (%cars+cdrs lists) + (if (pair? cars) + (begin + (apply f cars) ; Do head first, + (recur cdrs))))) ; then tail. + + ;; Fast path. + (let recur ((lis lis1)) + (if (not (null-list? lis)) + (begin + (f (car lis)) ; Do head first, + (recur (cdr lis))))))) ; then tail. ;;; filter, remove, partition ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;