Chapter 08

TAKIZAWA Yozo
2021.12.28に更新

# 01 関数型と簡易処理系

``````(1 2 3 4 5 6 7 8 9 10)
``````

# 02 関数評価とラムダ式

fpLISP
``````((lambda (a b) (if a b nil))
(eq 0 0) (eq 0 0))
``````
``````t
``````
fpLISP
``````((lambda (a b) (if a b nil))
(eq 0 1) (eq 0 0))
``````
``````nil
``````
fpLISP
``````((lambda (a b) (if a b nil))
(eq 0 0) (eq 0 1))
``````
``````nil
``````
fpLISP
``````((lambda (a b) (if a b nil))
(eq 0 1) (eq 0 1))
``````
``````nil
``````

# 03 ラムダ式を用いた再帰

2番目の引数に（`0`ではなく）`1`を指定する．

fpLISP
``````(((lambda (u) (u u))
(lambda (u)
(lambda (x r)
(if (eq x 0) r
((u u) (- x 1) (* r x))))))
10 1)
``````
``````3628800
``````

# 04 関数によるリスト処理

fpLISP
``````(((lambda (u) (u u))
(lambda (u)
(lambda (x r)
(if (eq x 0) r
((u u) (- x 1) (cons (- x 1) r))))))
10 nil)
``````

# 05 数値処理と記号処理

fpLISP
``````((lambda (assoc sublis1)
(sublis1
(quote ((a . alpha) (r . gamma) (d . delta)))
(quote (alpha beta gamma delta epsilon)))
assoc))
((lambda (u) (u u))
(lambda (u)
(lambda (k v)
(if (eq v nil) nil
(if (eq k (cdr (car v)))
(car (car v))
((u u) k (cdr v)))))))
((lambda (u) (u u))
(lambda (u)
(lambda (al L assoc)
(if (eq L nil) nil
(cons
((lambda (r) (if (eq r nil) (car L) r))
(assoc (car L) al))
((u u) al (cdr L) assoc)))))))
``````
``````(a beta r d epsilon)
``````

# 06 高階関数と遅延評価

``````-15
``````
``````(lambda nil x ((x . 18)))
``````
``````(5 4 3 2 1 0 -1 -2 -3 -4)
``````