Before LISPs Just Part of the Past ~#8 Rindoh~
description
Transcript of Before LISPs Just Part of the Past ~#8 Rindoh~
![Page 1: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/1.jpg)
BeforeLISPs
Just Part of the Past
〜 #8 Rindoh 〜
![Page 2: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/2.jpg)
Motivation 1
beginner
(defun stride-mapcar (stride fn lst) (labels ((rec (lst acc) (if (<= stride (length lst)) (rec (drop lst stride) (cons (funcall fn (car lst)) acc)) (nreverse acc)))) (rec lst nil)))
![Page 3: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/3.jpg)
Motivation 1
beginner
(stride-mapcar 2 #'symbol-name '(alpha a beta b)); => (“ALPHA” “BETA”)
(defun stride-mapcar (stride fn lst) (labels ((rec (lst acc) (if (<= stride (length lst)) (rec (drop lst stride) (cons (funcall fn (car lst)) acc)) (nreverse acc)))) (rec lst nil)))
![Page 4: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/4.jpg)
Motivation 1
beginner
(defun stride-mapcar (stride fn lst) (labels ((rec (lst acc) (if (<= stride (length lst)) (rec (drop lst stride) (cons (funcall fn (car lst)) acc)) (nreverse acc)))) (rec lst nil)))
![Page 5: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/5.jpg)
Motivation 1
beginner
(defun stride-mapcar (stride fn lst) (labels ((rec (lst acc) (if (nth (1- stride) lst) (rec (drop lst stride) (cons (funcall fn (car lst)) acc)) (nreverse acc)))) (rec lst nil)))
![Page 6: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/6.jpg)
Motivation 1
beginner
(defun stride-mapcar (stride fn lst) (labels ((rec (lst acc) (if (nth (1- stride) lst) (rec (drop lst stride) (cons (funcall fn (car lst)) acc)) (nreverse acc)))) (rec lst nil)))
(stride-mapcar 2 #'symbol-name '(alpha a beta b)); => (“ALPHA” “BETA”)
![Page 7: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/7.jpg)
Motivation 1● たまに短い値が返ってくる● とりあえず以前の定義で同じ値を返すのかが知りたい
– 同じ値を返すなら、アルゴリズムを見直す
– 違う値を返すなら、書き換えるときに無茶な仮定をしていないか見直す
● 関数定義を一時的に前の定義に戻して使う構文が欲しい– 呼び出し連鎖の中から値を取り出すのは面倒なので、レキシカルではなく大域的に(with-version ((stride-mapcar 0)) (foo ...)) ; FOO indirectly uses STRIDE-MAPCAR
beginner
![Page 8: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/8.jpg)
Motivation 1● たまに短い値が返ってくる● とりあえず以前の定義で同じ値を返すのかが知りたい
– 同じ値を返すなら、アルゴリズムを見直す
– 違う値を返すなら、書き換えるときに無茶な仮定をしていないか見直す
● 関数定義を一時的に前の定義に戻して使う構文が欲しい– 呼び出し連鎖の中から値を取り出すのは面倒なので、レキシカルではなく大域的に(with-version ((stride-mapcar 0)) (foo ...)) ; FOO indirectly uses STRIDE-MAPCAR
beginner
![Page 9: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/9.jpg)
Motivation 1● たまに短い値が返ってくる● とりあえず以前の定義で同じ値を返すのかが知りたい
– 同じ値を返すなら、アルゴリズムを見直す
– 違う値を返すなら、書き換えるときに無茶な仮定をしていないか見直す
● 関数定義を一時的に前の定義に戻して使う構文が欲しい– 呼び出し連鎖の中から値を取り出すのは面倒なので、レキシカルではなく大域的に(with-version ((stride-mapcar 0)) (foo ...)) ; FOO indirectly uses STRIDE-MAPCAR
beginner
![Page 10: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/10.jpg)
Motivation 1● たまに短い値が返ってくる● とりあえず以前の定義で同じ値を返すのかが知りたい
– 同じ値を返すなら、アルゴリズムを見直す
– 違う値を返すなら、書き換えるときに無茶な仮定をしていないか見直す
● 関数定義を一時的に前の定義に戻して使う構文が欲しい– 呼び出し連鎖の中から値を取り出すのは面倒なので、レキシカルではなく大域的に(with-version ((stride-mapcar 0)) (foo ...)) ; FOO indirectly uses STRIDE-MAPCAR
beginner
![Page 11: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/11.jpg)
Motivation 1● たまに短い値が返ってくる● とりあえず以前の定義で同じ値を返すのかが知りたい
– 同じ値を返すなら、アルゴリズムを見直す
– 違う値を返すなら、書き換えるときに無茶な仮定をしていないか見直す
● 関数定義を一時的に前の定義に戻して使いたい – 呼び出し連鎖の中から値を取り出すのは面倒なので、レキシカルではなく大域的に(with-version ((stride-mapcar 0)) (foo ...)) ; FOO indirectly uses STRIDE-MAPCAR
beginner
![Page 12: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/12.jpg)
Motivation 2
fledgling
![Page 13: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/13.jpg)
Motivation 2
fledgling
![Page 14: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/14.jpg)
Motivation 2
fledgling
● 定義を修正した時には既に期待していた答えを忘れている– ユニットテスト書く?
– 引数と返り値を全部保存しといたらいいんじゃ...
![Page 15: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/15.jpg)
Motivation 2
fledgling
● 定義を修正した時には既に期待していた答えを忘れている– ユニットテスト書く?
– 引数と返り値を全部保存しといたらいいんじゃ...
![Page 16: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/16.jpg)
Motivation 2
fledgling
● 定義を修正した時には既に期待していた答えを忘れている– ユニットテスト書く?
– 引数と返り値を全部保存しといたらいいんじゃ...
![Page 17: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/17.jpg)
Motivation 1
fledgling
beginner
関数定義に細工して定義を保存する
![Page 18: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/18.jpg)
Motivation 2
fledgling
beginner
関数定義に細工して実行時に
引数列と返り値を保存する
![Page 19: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/19.jpg)
Motivation 1&2
関数定義に細工する
fledglingnovice
![Page 20: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/20.jpg)
RINDOH:VDEFUN● vdefun name lambda-list form* => name● DEFUNフォームが保存される
● 適用のたびに引数とその評価結果が保存される
● VDEFUNフォームを評価すると、テストを実施する
● テストケース全てをパスしないと定義を更新できない
beginner
![Page 21: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/21.jpg)
RINDOH:VDEFUN● vdefun name lambda-list form* => name● DEFUNフォームが保存される
● 適用のたびに引数とその評価結果が保存される
● VDEFUNフォームを評価すると、テストを実施する
● テストケース全てをパスしないと定義を更新できない
fledgling
![Page 22: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/22.jpg)
RINDOH:VDEFUN● vdefun name lambda-list form* => name● DEFUNフォームが保存される
● 適用のたびに引数とその評価結果が保存される
● VDEFUNフォームを評価すると、テストを実施する
● テストケース全てをパスしないと定義を更新できない
fledgling
![Page 23: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/23.jpg)
RINDOH:VDEFUN● vdefun name lambda-list form* => name● DEFUNフォームが保存される
● 適用のたびに引数とその評価結果が保存される
● VDEFUNフォームを評価すると、テストを実施する
● テストケース全てをパスしないと定義を更新できない
fledglingbeginner
![Page 24: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/24.jpg)
RINDOH:WITH-VERSION● with-version (version-spec*) form* => result
● 指定されたバージョンの関数を使ってformを評価する
(with-version ((iota 3) (stride-mapcar 1)) (stride-mapcar 2 #'twice (iota 10)))
beginner
![Page 25: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/25.jpg)
その他● WITH-RAW-FN● DEFINE-TEST-FORM, DEFINE-TEST-CASE
● RUN-TEST● STDIFF
– 意外と見辛い
● 版管理?
![Page 26: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/26.jpg)
課題● 関数定義構文を囲むレキシカル環境が見えない
– (let ((counter -1)) (vdefun gen-id () (incf counter)))
● 呼び出しフォームを捕まえるために&RESTパラメータを強制して
いる
– (vdefun iota (n &optional (start 0)) ...)=> (defun iota (&rest params) ...)
● テストや定義をファイルに保存する形式
– VDEFUNフォーム vs エントリ (MAKE-LOAD-FORM)
![Page 27: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/27.jpg)
課題● 関数定義構文を囲むレキシカル環境が見えない
– (let ((counter -1)) (vdefun gen-id () (incf counter)))
● 呼び出しフォームを捕まえるために&RESTパラメータを強制して
いる
– (vdefun iota (n &optional (start 0)) ...)=> (defun iota (&rest params) ...)
● テストや定義をファイルに保存する形式
– VDEFUNフォーム vs エントリ (MAKE-LOAD-FORM)
![Page 28: Before LISPs Just Part of the Past ~#8 Rindoh~](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f9e04b4c905ad218b4865/html5/thumbnails/28.jpg)
課題● 関数定義構文を囲むレキシカル環境が見えない
– (let ((counter -1)) (vdefun gen-id () (incf counter)))
● 呼び出しフォームを捕まえるために&RESTパラメータを強制して
いる
– (vdefun iota (n &optional (start 0)) ...)=> (defun iota (&rest params) ...)
● テストや定義をファイルに保存する形式
– VDEFUNフォーム vs エントリ (MAKE-LOAD-FORM)