Next: , Previous: , Up: lists fold   [Index]


23.8.4 Derived folding

Function: and-fold-left* combine knil circ1 circ2 ...
Function: and-fold-right* combine knil circ1 circ2 ...
Syntax: and-fold-left*/stx combine knil circ1 circ2 ...
Syntax: and-fold-right*/stx combine knil circ1 circ2 ...

Like fold-left* and fold-right*, but stop the folding if the value returned by combine is #f, in which case the return value is #f.

Function: fold-left/pred pred knil circ

Apply pred to successive couples of elements from circ; return true if all the evaluations of pred were true. The iteration stops at the first #f return value from pred.

This function is implemented as:

(define (fold-left/pred pred knil ell)
  (and-fold-left*/stx (lambda (knil item)
                        (and (pred knil item) item))
                      knil ell))

and it can be used to implement predicates for ordering like <:

(fold-left/pred < 0 '(1 2 3 4 5 6))
⇒ 6

(fold-left/pred < 0 '(1 2 3 -4 5 6))
⇒ #f