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

# MATH build up functions of several variables
[hear] (= ((? x / ? y / - (x) (y)) 7 4) 3);

[hear] (= ((? x / ? y / - (x) (y)) 12 8) 4);

[hear] (= ((? x / ? y / - (x) (y)) 12 8) 4);

[hear] (= ((? x / ? y / - (x) (y)) 8 2) 6);

[hear] (= ((? x / ? y / - (x) (y)) 14 5) 9);

[hear] (define last /
? x /
list-ref (x) (- (list-length / x) 1));

[hear] (define except-last /
? x /
if (> (list-length / x) 1)
(prepend
x)
(except-last /
tail /
x))
(vector));

# test last and except-last
[hear] (= 15 (last / vector 4 5 15));

[hear] (list= (vector 4 5)
(except-last /
vector 4 5 15));

[hear] (intro lambda);

[hear] (define prev-translate / translate);

[hear] (define translate /
let ((prev (prev-translate)))
(? x /
if (number? /
x)
(prev /
x)
(if (= (head / x) lambda)
(let ((formals (head / tail / x))
(body (head / tail / tail / x)))
(if (> (list-length / formals) 0)
(translate
(vector
lambda
(except-last /
formals)
(vector ? (last / formals) (body))))
(translate (body))))
(prev /
x))));

# test lambda
[hear] (= ((lambda (x y) (- (x) (y))) 3 2) 1);

[hear] (= ((lambda (x y) (- (x) (y))) 6 6) 0);

[hear] (= ((lambda (x y) (- (x) (y))) 14 8) 6);

[hear] (= ((lambda (x y) (- (x) (y))) 10 8) 2);

[hear] (= ((lambda (x y) (- (x) (y))) 11 5) 6);

[hear] (define apply /
lambda (x y)
(if (list= (y) (vector))
(x)
(apply ((x) (head / y)) (tail / y))));

[hear] (= (apply (lambda (x y) (- (x) (y))) (vector 14 9))
5);

[hear] (= (apply (lambda (x y) (- (x) (y))) (vector 3 3))
0);

[hear] (= (apply (lambda (x y) (- (x) (y))) (vector 7 1))
6);

[hear] (= (apply (lambda (x y) (- (x) (y))) (vector 9 4))
5);

[hear] (= (apply (lambda (x y) (- (x) (y))) (vector 5 5))
0);