(defun report-result (result form)
(format t "~:[FAIL~;PASS~] ... ~a~%" result form)
result)
(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
,@body))
(defmacro combine-results (&body forms)
(with-gensyms (result)
`(let ((,result t))
,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
,result)))
(defmacro check (&body forms)
`(combine-results
,@(loop for f in forms collect `(report-result ,f ',f))))
(defun test-+ ()
(check (= (+ 1 2) 3)
(= (+ 1 2 3) 6)
(= (+ -1 -3) -4)))
わからない場所のメモ
* formatの書式
; ~:[偽の場合~;真の場合~]
(format t "~:[FAIL~;PASS~] ... ~a~%" result form)
* loopの書式
ループキーワードというものがある
for, collect, sum, count, do, finally
collectはリストを返すようだ
; in前置詞句
* (loop for var in '(1 2 3 4) collect var)
(1 2 3 4)
; ベクタの場合はinではなくacross
* (loop for x across "abcd" collect x)
(#\a #\b #\c #\d)
;複数指定可能
(loop
for item in list
for n from 1 to 10
do (something))
0 件のコメント:
コメントを投稿