Function: (mapn f a b . xs) : "map n". Primary usage: (mapn f a b) = (map f (range a b)). Extra argument pairs will yield nested applications of 'mapn, with f applied to a kind of product of all ranges. The implementation and a demonstration will make this clearer:
(def mapn (f a b . xs)
(if no.xs
(map f (range a b))
(mapn [apply mapn (fn args (apply f _ args))
xs]
a b)))
arc> (mapn square 1 10)
(1 4 9 16 25 36 49 64 81 100)
arc> (mapn list 1 3 20 22)
(((1 20) (1 21) (1 22)) ((2 20) (2 21) (2 22)) ((3 20) (3 21) (3 22)))
'mapn is very nice for testing out a function on a numerical range, especially repeatedly. Also, given the 'grid function, we can construct two-dimensional tables of a function extremely easily: