Merge from S48 repository
Original commit message from Mike Sperber: Subject: Add implementation of FOR-EACH to SRFI-1 This was missing from Olin's reference implementation. Note that currently, the native versions of MAP and FOR-EACH already implement the extended semantics specified by SRFI 1. However, we might want to enforce the R5RS restrictions to MAP and FOR-EACH at some time in the future, so it still makes sense to have separate implementations in SRFI 1.
This commit is contained in:
parent
523b402079
commit
84f85be750
|
@ -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
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
Loading…
Reference in New Issue