EoPL reading (62) 2.2 An Abstraction for Inductive Data Type

define-datatype って強力。On Lisp にあるボトムアップデザイン? それにしても BNF から直感的に書けてる、というのはなかなか凄い。
とりあえず occurs-free? の試験の続きを書きます。
以下を追加。

(test-section "lambda-exp")
(test* "occurs free (lambda-exp)"
       #t
       (occurs-free? 'y '(lambda-exp x (var-exp y))))
(test* "not occurs free (lambda-exp)"
       #f
       (occurs-free? 'y '(lambda-exp y (var-exp y))))
(test* "not occurs free (lambda-exp)"
       #f
       (occurs-free? 'y '(lambda-exp x (var-exp x))))

(test-section "app-exp")
(test* "occurs free (app-exp)"
       #t
       (occurs-free? 'y '(app-exp (lambda-exp x (var-exp y)) (var-exp y))))

(test* "occurs free (app-exp)"
       #t
       (occurs-free? 'y '(app-exp (lambda-exp y (var-exp y)) (var-exp y))))

app-exp な試験が通らない、と思ったら以下なバグが。

	   (app-exp (rator rand)
		    (or (occurs-free? rator)
			(occurs-free? rand))))))

最初は上記の試験が悪いの? って思ってたんですがテキスト見て書いた実装が嘘でした。もう少し試験を追加。

(test* "not occurs free (app-exp)"
       #f
       (occurs-free? 'y '(app-exp (lambda-exp y (var-exp y)) (var-exp x))))

次に出てくる parse とか unparse なんかの試験を今から検討。なんと言えば良いか分かりませんが define-syntax 強力杉。