-
Notifications
You must be signed in to change notification settings - Fork 0
/
map-star.scm
28 lines (27 loc) · 1.04 KB
/
map-star.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
;; Copyright (C) David Benoit 2017
;; Author: David Benoit
;; map*
;;
;; Unleash the full power of mapping variardic functions.
;;
;; Scheme's built in map procedure operates on an arbitrary number
;; of equal length lists. This is not a problem when mapping
;; with fixed-argument functions, or mapping variardic functions
;; over an explicit number of lists.
;;
;; The limitation of scheme's built in map occurs when it
;; would be useful to map over an arbitrary number of lists
;; with a variardic function.
;;
;; map* allows programmers to map over an arbitrarily long list of lists
;; with a variardic function. It also allows using a fixed-argument
;; function with a list of lists, provided the length of the first
;; list dimension is equal to the number of arguments the lambda function
;; takes. All second dimension lists must be of equal length, or map*
;; will fail (just like regular map).
(define (map* lmbda list-of-lists)
(call-with-values
(lambda ()
(apply values
(cons lmbda list-of-lists)))
map))