pcl读书笔记
大致看了下,网上有人晒这本书的笔记,被吸引去。现在开始学习。
写于2012年02月15日 星期三 15时45分41秒
用lisp编写mp3数据库
不说啥了。直接上代码
;录制cd
(defun make-cd (title artist rating ripped)
(list :title title :artist artist :rating rating :ripped ripped))
;定义数据库
(defvar *db* nil)
;添加cd
(defun add-record (cd) (push cd *db*))
(add-record (make-cd "Roses" "Kathy Mattea" 7 t))
(add-record (make-cd "Fly" "Dixie Chick" 8 t))
(add-record (make-cd "Home" "Dixie Chick" 7 t))
;格式化输出
(defun dump-db ()
(dolist (cd *db*)
(format t "~{~a: ~10t~a~%~}~%" cd)))
;用户交互
(defun prompt-read (prompt)
(format *query-io* "~a: " prompt)
(force-output *query-io*)
(read-line *query-io*))
(defun prompt-for-cd ()
(make-cd
(prompt-read "Title")
(prompt-read "Artist")
(or (parse-integer (prompt-read "Rating") :junk-allowed t) 0)
(y-or-n-p "Ripped [y/n]: ")))
;包装成循环函数
(defun add-cds ()
(loop (add-record (prompt-for-cd))
(if (not (y-or-n-p "Another? [y/n]: "))(return))))
;保存和加载数据库
(defun save-db (filename)
(with-open-file (out filename
:direction :output
:if-exists :supersede)
(with-standard-io-syntax
(print *db* out))))
(defun load-db (filename)
(with-open-file (in filename)
(with-standard-io-syntax
(setf *db* (read in)))))
好吧,后面的数据库什么我看不懂了。。
2012年02月18日 星期六 13时36分19秒
语法与语义
-
S表达式
-
atom
- symbols
- digits
- strings
-
list
- function call form
- macro form
- special form
-
atom
-
tnil等价 -
格式化lisp代码
- 缩进
- 注释
函数
-
defun -
形参列表
-
&optional -
&key -
&rest
-
-
函数返回值
-
return-from
-
-
作为数据的函数——高阶函数
-
funcall -
apply
-
-
匿名函数——
lambda
变量
-
lexical
-
let与包
-
-
dynamic
-
defvar -
defparameter
-
-
常量
-
defconstant
-
-
赋值
-
setf -
ncf/decf/rotatef/shiftf
-
标准宏
-
whenunless -
cond -
andornot -
循环
-
do -
dolist -
dotimes -
loop
-
定义宏
- runtime/(macro expansion time)
- defmacro
-
宏形参
-
&body
-
-
生成展开式unquote
-
, - ,@
-
2012年04月02日 星期一 21时56分58秒
发现好久没看了,一个人看进步好慢,也没兴致。但还是有兴趣的,不行考完研在说。