Section 20
Want more of a challenge? View in iconic form (experimental)



       # MATH show map function for applying a function across the elements of a list
[hear] (define map /
         lambda (p lst)
          (if (> (list-length / lst) 0)
            (prepend
              (p (head / lst))
              (map (p) (tail / lst)))
            (vector)));

[hear] (= (map (? x / * (x) 2) (vector 12 4 13))
           (vector 24 8 26));

[hear] (= (map (? x / * (x) 2) (vector 7 15 19 14))
           (vector 14 30 38 28));

[hear] (= (map (? x / * (x) 2) (vector 2 4 17 6 8))
           (vector 4 8 34 12 16));

[hear] (= (map (? x / * (x) 2) (vector 15 18 17 10 16 4))
           (vector 30 36 34 20 32 8));

[hear] (= (map (? x 42) (vector 1 19 5))
           (vector 42 42 42));

[hear] (= (map (? x 42) (vector 8 9 10 3))
           (vector 42 42 42 42));

[hear] (= (map (? x 42) (vector 6 12 11 13 8))
           (vector 42 42 42 42 42));

[hear] (= (map (? x 42) (vector 1 7 10 0 18 9))
           (vector 42 42 42 42 42 42));

[hear] (define crunch /
         lambda (p lst)
          (if (>= (list-length / lst) 2)
            (p (head / lst) (crunch (p) (tail / lst)))
            (if (= (list-length / lst) 1)
              (head /
               lst)
              (undefined))));

[hear] (= (crunch (+) (vector 13 9 14)) 36);

[hear] (= (crunch (+) (vector 14 8 6 19)) 47);

[hear] (= (crunch (+) (vector 17 10 4 16 15)) 62);

[hear] (= (crunch (+) (vector 18 15 4 3 8 10)) 58);