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

[hear] (= ((? x / ? y / - (x) (y)) 8 7) 1);

[hear] (= ((? x / ? y / - (x) (y)) 13 9) 4);

[hear] (= ((? x / ? y / - (x) (y)) 15 9) 6);

[hear] (= ((? x / ? y / - (x) (y)) 8 5) 3);

[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] (= (? x / - (x) 5) (lambda (x) (- (x) 5)));

[hear] (= (? x /
? y /
- (x) (y))
(lambda (x y) (- (x) (y))));

[hear] (= ((lambda (x y) (- (x) (y))) 9 1) 8);

[hear] (= ((lambda (x y) (- (x) (y))) 15 7) 8);

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

[hear] (= ((lambda (x y) (- (x) (y))) 11 8) 3);

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

[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 8 1))
7);

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

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

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

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