SketchyLISP Reference |
Copyright (C) 2007 Nils M Holm |
<<[list?] | [Index] | [map-car]>> |
Conformance: R5RS Scheme
Purpose:
Map a function over lists.
The function
f
is applied to the list containing the
car
part of each argument, giving the first
member of the result list.
Map
then proceeds with the
cadr
parts of each list, giving the next member of the
result list, etc.
All lists passed to
map
must have the same length.
Arguments:
F - function to apply
A* ... - lists
Implementation:
(define (map f . a*) (letrec ((carof (lambda (a) (map-car car a))) (cdrof (lambda (a) (map-car cdr a))) (_map (lambda (a* r) (cond ((null? (car a*)) (reverse r)) (else (_map (cdrof a*) (cons (apply f (carof a*)) r))))))) (cond ((null? a*) (bottom '(too few arguments to map))) (else (_map a* '())))))
Example:
(map cons '(a b c) '(d e f)) => ((a . d) (b . e) (c . f))
See also:
member,
list?,
fold-left,
fold-right.
<<[list?] | [Index] | [map-car]>> |