あろえの備忘録

移転しました http://blog.vitamin11.org/

Lisp備忘録

今日写経したコード
(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))

Emacsの備忘録Lispの今日の写経

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies