EoPL reading (52) 2.2 An Abstraction for Inductive Data Type
UT 大事ですが、パラで EoPL なナニも進める方向で。
# 休みなんでこっち方面に稼動がなかなか向けれない
とりあえずテキストに例示されているソレを確認。とりあえず bintree から。
(use gauche.test) (add-load-path ".") (load "define-datatype") (test-start "define-datatype") (test-section "bintree") (define-datatype bintree bintree? (leaf-node (datum number?)) (interior-node (key symbol?) (left bintree?) (right bintree?))) (define tree-a (interior-node 'a (leaf-node 2) (leaf-node 3))) (define tree-b (interior-node 'b (leaf-node -1) tree-a)) (define tree-c (interior-node 'c tree-b (leaf-node 1))) (test* "tree-a'" '(interior-node a (leaf-node 2) (leaf-node 3)) tree-a) (test* "tree-b" '(interior-node b (leaf-node -1) (interior-node a (leaf-node 2) (leaf-node 3))) tree-b) (test* "tree-c" '(interior-node c (interior-node b (leaf-node -1) (interior-node a (leaf-node 2) (leaf-node 3))) (leaf-node 1)) tree-c) (test* "predicate (1)" #t (bintree? tree-a)) (test* "predicate (2)" #t (bintree? tree-b)) (test* "predicate (3)" #t (bintree? tree-c)) (test-end)
試験実行。
$ make Testing define-datatype ... passed. rms@debian:~/chroot.home/1.programming/2.EoPL/3.2.2/1.bintree$ cat test.log define-datatype.scm version J3 2002-01-02 10:55 Testing define-datatype ======================================================= <bintree>---------------------------------------------------------------------- test tree-a', expects (interior-node a (leaf-node 2) (leaf-node 3)) ==> ok test tree-b, expects (interior-node b (leaf-node -1) (interior-node a (leaf-node 2) (leaf-node 3))) ==> ok test tree-c, expects (interior-node c (interior-node b (leaf-node -1) (interior-node a (leaf-node 2) (leaf-node 3))) (leaf-node 1)) ==> ok test predicate (1), expects #t ==> ok test predicate (2), expects #t ==> ok test predicate (3), expects #t ==> ok passed. $
なんかタグ付けなリストになっている模様。てか、define-datatype の何処でこれをセットしてるのか、と言いつつソース見てみたら以下な部分?
(define Type-name (cons '(Variant-name ...) '((Variant-name Field-name ...) ...)))
や、なんか違うぞ、と言いつつ gosh にて確認。
gosh> interior-node #<closure interior-node> gosh> leaf-node #<closure leaf-node> gosh> bintree ((leaf-node interior-node) (leaf-node datum) (interior-node key left right)) gosh>
最後のは何だろ。ってか、正に上記 Type-name が戻すナニか。なら、上記の interior-node だの leaf-node だのが戻す手続きは何だ、というとおそらくは
(define Variant-name
なソレなのか。やっぱきちんとソース読めって事ッスか?