See it run
LISPEX
(fold-right cons (list) (list 1 2 3))Observed result
OUTPUT
(1 2 3)How to reason about it
- List, string, and vector traversal is left to right.
fold-rightis the deliberate exception, and it calls(f element accumulator)from the right. reduceandfold-leftare the same left fold and call(f accumulator element).all?andany?stop as soon as the answer is known. Their predicate must return#tor#f, whilefilteruses ordinary Lispex truthiness instead.for-eachruns for effect, accepts any number of callback values, and returns zero values itself.- Callback errors and one-shot escapes stay inside the program that runs your
rule. LIL does not hand the procedure to the host's own
applyor to a host callback.
Callback contracts
| Signature | Traversal / result | Value context |
|---|---|---|
| (map proc list) | left-to-right, fresh proper list | callback exactly one value |
| (filter predicate list) | left-to-right, retained elements | predicate exactly one value, and only #f rejects |
| (all? predicate list), (any? predicate list) | left-to-right and stopping early, strict boolean | predicate exactly one boolean |
| (reduce proc init list), (fold-left proc init list) | left accumulator | callback exactly one value |
| (fold-right proc init list) | right accumulator | callback exactly one value |
| (string-map proc string), (vector-map proc vector) | left-to-right, fresh result | callback exactly one value, and a string result must be a character |
| string/vector/list for-each | left-to-right effects, overall zero values | callback results are discarded |
| (apply proc arg ... final-list) | shared application dispatcher, tail-safe | every value the procedure returns is preserved |
A common mistake
These procedures accept one collection, not the multi-list variants offered by some Scheme systems. String characters and vector elements are snapshotted before the first callback, so mutating the source vector during traversal does not change which elements are visited.
Keep going
The guide assembles these procedures into one working pipeline, and the index places them among the other families.