今日は,『プログラミングGauche』の
- 10章 テストと例外処理
- 11章 評価モデル
- 12章 数値
- 13章 文字と文字列の処理
- 14章 入出力
- 15章 テキストの構築
を読みました。
10章
「10.3 テストフレームワークを書いてみる」ではgauche.testのサブセットを実装します。実際にテストする部分がなかったので,mycode-test.scmと同様のテストをするように書いてみました。
;; mycode-test2.scm (define *num-tests* 0) (define *num-passes* 0) (define *num-failures* 0) (define (mytest-start name) (print "Testing " name " ...") (set! *num-tests* 0) (set! *num-passes* 0) (set! *num-failures* 0)) (define (mytest-end) (print *num-tests* " tests, " *num-passes* " passed, " *num-failures* " failed.")) (define (mytest label expected thunk . options) (let-optionals* options ((cmp-fn equal?)) (print "Testing " label " ...") (inc! *num-tests*) (let ((result (guard (e (else 'test-error)) (thunk)))) (cond [(cmp-fn expected result) (inc! *num-passes*) (print " : OK")] [else (inc! *num-failures*) (print " : ERROR: expecting " expected ", but got " result)])) )) (mytest-start "mycode") (load "./mycode") (mytest "last-pair #1" '(3) (lambda () (last-pair '(1 2 3)))) (mytest "last-pair #2" '(1) (lambda () (last-pair '(1)))) (mytest "last-pair #3" '(2 . 3) (lambda () (last-pair '(1 2 . 3)))) ;; *test-error* ではなく,'test-error に変更 (mytest "last-pair / error" 'test-error (lambda () (last-pair '()))) (mytest-end)
11章
疑問点なのですが,図11-1〜図11-4で「大域環境フレーム」とあるのが,図11-5以降では「環境フレーム0」となっています。これは,「環境フレーム0」が「大域環境フレーム」,「環境フレーム1」以降が「局所環境フレーム」と理解すればいいのだろうか?
13章
p188に,
gosh> (and-let* ((m (#/bc/ "abcd"))) (map (cut m <>) '(before 0 after))) ("a" "bc" "d")
が出てきますが,なんでand-let*を使っているのかが疑問です。letではダメなのでしょうか?
gosh> (let ((m (#/bc/ "abcd"))) (map (cut m <>) '(before 0 after))) ("a" "bc" "d")