1、《ANSI Common Lisp》中文版

http://acl.readthedocs.io/en/latest/zhCN/index.html

备用地址-看云:https://www.kancloud.cn/kancloud/acl

备用地址-W3C:https://www.w3cschool.cn/ansi_common_lisp/

github地址:https://github.com/acl-translation/acl-chinese

2、《On Lisp》 中文版

https://www.kancloud.cn/ituring/on-lisp

备用地址-W3C:https://www.w3cschool.cn/on_lisp/

3、《Practical Common Lisp》

英语原文电子书:http://www.gigamonkeys.com/book/

4、易百教程

Lisp教程:https://www.yiibai.com/lisp/

5、相关网站

深度开源:http://www.open-open.com/lib/list/294

segmentfault:https://segmentfault.com/t/lisp

common-lisp:https://common-lisp.net/

一个国外教程网:https://www.tutorialspoint.com/lisp/index.htm

6、网易云课堂

《Lisp,Haskell,Python的天空之城》(收费课程,126块,有点小贵):http://study.163.com/course/introduction/1003603054.htm

7、Lisp书单

1)《Common Lisp: A Gentle Introduction to Symbolic Computation》很好很详细的入门书籍,基本上是零基础的入门。2)《ANSI Common LISP》Paul大神的作品,他的《黑客与画家》是必读的经典,会改变三观的说。3)《Structure and Interpretation of Computer Programs》都是Lisp,不过这本好像是基础,用的是scheme,看过一点,是内功。4)《Practical Common Lisp》大神田春翻译的中文版《实用Common Lisp编程》已经出版。5)《On Lisp》也是Paul大神的作品,好像是进阶修炼版本。6)《Let Over Lambda》看名字就知道是Lambda表达式,讲宏的意思,这种高级特性慢慢来吧。7)《Paradigms of Artificial Intelligence Programming:Case Studies in Common Lisp》总算到人工智能部分了,这本是没有现成中文版了。8)《Artificial Intelligence :A Modern Approach》《人工智能:一种现代方法》看了个开头,从人工智能在各个学科中的基础开始,一开始就来列人名了,哲学,数学,心理学,计算工程,认知科学,从古希腊到近现代,有一个算一个大神全到了。很有意思9)《Common Lisp:The language》,堪比C++ Primer的长度,1100多页,大神说犹如高峰,待攀。10)《GNU Emacs Lisp编程入门》11)《Common Lisp Recipes》
; The code in this file was mechanically extracted from the TeX
; source files of _Ansi Common Lisp_, except for bst-remove and
; bst-delete and their subroutines, which replace broken versions
; in the book.; If you have questions or comments about this code, or you want
; something I didn't include, send mail to lispcode@paulgraham.com.; This code is copyright 1995 by Paul Graham, but anyone who wants
; to use it is free to do so.; *** list ***(defun compress (x)(if (consp x)(compr (car x) 1 (cdr x))x))(defun compr (elt n lst)(if (null lst)(list (n-elts elt n))(let ((next (car lst)))(if (eql next elt)(compr elt (+ n 1) (cdr lst))(cons (n-elts elt n)(compr next 1 (cdr lst)))))))(defun n-elts (elt n)(if (> n 1)(list n elt)elt))(defun uncompress (lst)(if (null lst)nil(let ((elt (car lst))(rest (uncompress (cdr lst))))(if (consp elt)(append (apply #'list-of elt)rest)(cons elt rest)))))(defun list-of (n elt)(if (zerop n)nil(cons elt (list-of (- n 1) elt))))(defun mirror? (s)(let ((len (length s)))(and (evenp len)(let ((mid (/ len 2)))(equal (subseq s 0 mid)(reverse (subseq s mid)))))))(defun shortest-path (start end net)(bfs end (list (list start)) net))(defun bfs (end queue net)(if (null queue)nil(let ((path (car queue)))(let ((node (car path)))(if (eql node end)(reverse path)(bfs end(append (cdr queue)(new-paths path node net))net))))))(defun new-paths (path node net)(mapcar #'(lambda (n)(cons n path))(cdr (assoc node net)))); *** dat ***(defun bin-search (obj vec)(let ((len (length vec)))(and (not (zerop len))(finder obj vec 0 (- len 1)))))(defun finder (obj vec start end)(let ((range (- end start)))(if (zerop range)(if (eql obj (aref vec start))objnil)(let ((mid (+ start (round (/ range 2)))))(let ((obj2 (aref vec mid)))(if (< obj obj2)(finder obj vec start (- mid 1))(if (> obj obj2)(finder obj vec (+ mid 1) end)obj)))))))(defun mirror? (s)(let ((len (length s)))(and (evenp len)(do ((forward 0 (+ forward 1))(back (- len 1) (- back 1)))((or (> forward back)(not (eql (elt s forward)(elt s back))))(> forward back))))))(defun second-word (str)(let ((p1 (+ (position #\  str) 1)))(subseq str p1 (position #\  str :start p1))))(defun tokens (str test start)(let ((p1 (position-if test str :start start)))(if p1(let ((p2 (position-if #'(lambda (c)(not (funcall test c)))str :start p1)))(cons (subseq str p1 p2)(if p2(tokens str test p2)nil)))nil)))(defun constituent (c)(and (graphic-char-p c)(not (char= c #\  ))))(defun parse-date (str)(let ((toks (tokens str #'constituent 0)))(list (parse-integer (first toks))(parse-month   (second toks))(parse-integer (third toks)))))(defconstant month-names#("jan" "feb" "mar" "apr" "may" "jun""jul" "aug" "sep" "oct" "nov" "dec"))(defun parse-month (str)(let ((p (position str month-names:test #'string-equal)))(if p(+ p 1)nil)))(defun read-integer (str)(if (every #'digit-char-p str)(let ((accum 0))(dotimes (pos (length str))(setf accum (+ (* accum 10)(digit-char-p (char str pos)))))accum)nil))(defstruct (node (:print-function(lambda (n s d)(format s "#<~A>" (node-elt n)))))elt (l nil) (r nil))(defun bst-insert (obj bst <)(if (null bst)(make-node :elt obj)(let ((elt (node-elt bst)))(if (eql obj elt)bst(if (funcall < obj elt)(make-node:elt elt:l   (bst-insert obj (node-l bst) <):r   (node-r bst))(make-node:elt elt:r   (bst-insert obj (node-r bst) <):l   (node-l bst)))))))(defun bst-find (obj bst <)(if (null bst)nil(let ((elt (node-elt bst)))(if (eql obj elt)bst(if (funcall < obj elt)(bst-find obj (node-l bst) <)(bst-find obj (node-r bst) <))))))(defun bst-min (bst)(and bst(or (bst-min (node-l bst)) bst)))(defun bst-max (bst)(and bst(or (bst-max (node-r bst)) bst)))(defun bst-traverse (fn bst)(when bst(bst-traverse fn (node-l bst))(funcall fn (node-elt bst))(bst-traverse fn (node-r bst)))); >>> Replaces bst-remove from book, which was broken.(defun bst-remove (obj bst <)(if (null bst)nil(let ((elt (node-elt bst)))(if (eql obj elt)(percolate bst)(if (funcall < obj elt)(make-node:elt elt:l (bst-remove obj (node-l bst) <):r (node-r bst))(make-node:elt elt:r (bst-remove obj (node-r bst) <):l (node-l bst)))))))(defun percolate (bst)(let ((l (node-l bst)) (r (node-r bst)))(cond ((null l) r)((null r) l)(t (if (zerop (random 2))(make-node :elt (node-elt (bst-max l)):r r:l (bst-remove-max l))(make-node :elt (node-elt (bst-min r)):r (bst-remove-min r):l l))))))(defun bst-remove-min (bst)(if (null (node-l bst))(node-r bst)(make-node :elt (node-elt bst):l   (bst-remove-min (node-l bst)):r   (node-r bst))))(defun bst-remove-max (bst)(if (null (node-r bst))(node-l bst)(make-node :elt (node-elt bst):l (node-l bst):r (bst-remove-max (node-r bst))))); *** con ***(defun read-integer (str)(let ((accum 0))(dotimes (pos (length str))(let ((i (digit-char-p (char str pos))))(if i(setf accum (+ (* accum 10) i))(return-from read-integer nil))))accum))(defun factorial (n)(do ((j n (- j 1))(f 1 (* j f)))((= j 0) f)))(defconstant month#(0 31 59 90 120 151 181 212 243 273 304 334 365))(defconstant yzero 2000)(defun leap? (y)(and (zerop (mod y 4))(or (zerop (mod y 400))(not (zerop (mod y 100))))))(defun date->num (d m y)(+ (- d 1) (month-num m y) (year-num y)))(defun month-num (m y)(+ (svref month (- m 1))(if (and (> m 2) (leap? y)) 1 0)))(defun year-num (y)(let ((d 0))(if (>= y yzero)(dotimes (i (- y yzero) d)(incf d (year-days (+ yzero i))))(dotimes (i (- yzero y) (- d))(incf d (year-days (+ y i)))))))(defun year-days (y) (if (leap? y) 366 365))(defun num->date (n)(multiple-value-bind (y left) (num-year n)(multiple-value-bind (m d) (num-month left y)(values d m y))))(defun num-year (n)(if (< n 0)(do* ((y (- yzero 1) (- y 1))(d (- (year-days y)) (- d (year-days y))))((<= d n) (values y (- n d))))(do* ((y yzero (+ y 1))(prev 0 d)(d (year-days y) (+ d (year-days y))))((> d n) (values y (- n prev))))))(defun num-month (n y)(if (leap? y)(cond ((= n 59) (values 2 29))((> n 59) (nmon (- n 1)))(t        (nmon n)))(nmon n)))(defun nmon (n)(let ((m (position n month :test #'<)))(values m (+ 1 (- n (svref month (- m 1)))))))(defun date+ (d m y n)(num->date (+ (date->num d m y) n))); *** fn ***(defun single? (lst)(and (consp lst) (null (cdr lst))))(defun append1 (lst obj)(append lst (list obj)))(defun map-int (fn n)(let ((acc nil))(dotimes (i n)(push (funcall fn i) acc))(nreverse acc)))(defun filter (fn lst)(let ((acc nil))(dolist (x lst)(let ((val (funcall fn x)))(if val (push val acc))))(nreverse acc)))(defun most (fn lst)(if (null lst)(values nil nil)(let* ((wins (car lst))(max (funcall fn wins)))(dolist (obj (cdr lst))(let ((score (funcall fn obj)))(when (> score max)(setf wins objmax  score))))(values wins max))))(defun make-adder (n)#'(lambda (x)(+ x n)))(let ((counter 0))(defun reset ()(setf counter 0))(defun stamp ()(setf counter (+ counter 1))))(defun compose (&rest fns)(destructuring-bind (fn1 . rest) (reverse fns)#'(lambda (&rest args)(reduce #'(lambda (v f) (funcall f v))rest:initial-value (apply fn1 args)))))(defun disjoin (fn &rest fns)(if (null fns)fn(let ((disj (apply #'disjoin fns)))#'(lambda (&rest args)(or (apply fn args) (apply disj args))))))(defun conjoin (fn &rest fns)(if (null fns)fn(let ((conj (apply #'conjoin fns)))#'(lambda (&rest args)(and (apply fn args) (apply conj args))))))(defun curry (fn &rest args)#'(lambda (&rest args2)(apply fn (append args args2))))(defun rcurry (fn &rest args)#'(lambda (&rest args2)(apply fn (append args2 args))))(defun always (x) #'(lambda (&rest args) x))(defun fib (n)(if (<= n 1)1(+ (fib (- n 1))(fib (- n 2)))))(defun fib (n)(do ((i  n (- i 1))(f1 1 (+ f1 f2))(f2 1 f1))((<= i 1) f1))); *** io ***(defun pseudo-cat (file)(with-open-file (str file :direction :input)(do ((line (read-line str nil 'eof)(read-line str nil 'eof)))((eql line 'eof))(format t "~A~%" line))))(defstruct bufvec (start -1) (used -1) (new -1) (end -1))(defun bref (buf n)(svref (buf-vec buf)(mod n (length (buf-vec buf)))))(defun (setf bref) (val buf n)(setf (svref (buf-vec buf)(mod n (length (buf-vec buf))))val))(defun new-buf (len)(make-buf :vec (make-array len)))(defun buf-insert (x b)(setf (bref b (incf (buf-end b))) x))(defun buf-pop (b)(prog1(bref b (incf (buf-start b)))(setf (buf-used b) (buf-start b)(buf-new  b) (buf-end   b))))(defun buf-next (b)(when (< (buf-used b) (buf-new b))(bref b (incf (buf-used b)))))(defun buf-reset (b)(setf (buf-used b) (buf-start b)(buf-new  b) (buf-end   b)))(defun buf-clear (b)(setf (buf-start b) -1 (buf-used  b) -1(buf-new   b) -1 (buf-end   b) -1))(defun buf-flush (b str)(do ((i (1+ (buf-used b)) (1+ i)))((> i (buf-end b)))(princ (bref b i) str)))(defun file-subst (old new file1 file2)(with-open-file (in file1 :direction :input)(with-open-file (out file2 :direction :output:if-exists :supersede)(stream-subst old new in out))))(defun stream-subst (old new in out)(let* ((pos 0)(len (length old))(buf (new-buf len))(from-buf nil))(do ((c (read-char in nil :eof)(or (setf from-buf (buf-next buf))(read-char in nil :eof))))((eql c :eof))(cond ((char= c (char old pos))(incf pos)(cond ((= pos len)            ; 3(princ new out)(setf pos 0)(buf-clear buf))((not from-buf)         ; 2(buf-insert c buf))))((zerop pos)                   ; 1(princ c out)(when from-buf(buf-pop buf)(buf-reset buf)))(t                             ; 4(unless from-buf(buf-insert c buf))(princ (buf-pop buf) out)(buf-reset buf)(setf pos 0))))(buf-flush buf out))); *** sym ***(defparameter *words* (make-hash-table :size 10000))(defconstant maxword 100)(defun read-text (pathname)(with-open-file (s pathname :direction :input)(let ((buffer (make-string maxword))(pos 0))(do ((c (read-char s nil :eof)(read-char s nil :eof)))((eql c :eof))(if (or (alpha-char-p c) (char= c #\'))(progn(setf (aref buffer pos) c)(incf pos))(progn(unless (zerop pos)(see (intern (string-downcase(subseq buffer 0 pos))))(setf pos 0))(let ((p (punc c)))(if p (see p)))))))))(defun punc (c)(case c(#\. '|.|) (#\, '|,|) (#\; '|;|)(#\! '|!|) (#\? '|?|) ))(let ((prev `|.|))(defun see (symb)(let ((pair (assoc symb (gethash prev *words*))))(if (null pair)(push (cons symb 1) (gethash prev *words*))(incf (cdr pair))))(setf prev symb)))(defun generate-text (n &optional (prev '|.|))(if (zerop n)(terpri)(let ((next (random-next prev)))(format t "~A " next)(generate-text (1- n) next))))(defun random-next (prev)(let* ((choices (gethash prev *words*))(i (random (reduce #'+ choices:key #'cdr))))(dolist (pair choices)(if (minusp (decf i (cdr pair)))(return (car pair)))))); *** num ***(defun palindrome? (x)(let ((mid (/ (length x) 2)))(equal (subseq x 0 (floor mid))(reverse (subseq x (ceiling mid))))))(defun sq (x) (* x x))(defun mag (x y z)(sqrt (+ (sq x) (sq y) (sq z))))(defun unit-vector (x y z)(let ((d (mag x y z)))(values (/ x d) (/ y d) (/ z d))))(defstruct (point (:conc-name nil))x y z)(defun distance (p1 p2)(mag (- (x p1) (x p2))(- (y p1) (y p2))(- (z p1) (z p2))))(defun minroot (a b c)(if (zerop a)(/ (- c) b)(let ((disc (- (sq b) (* 4 a c))))(unless (minusp disc)(let ((discrt (sqrt disc)))(min (/ (+ (- b) discrt) (* 2 a))(/ (- (- b) discrt) (* 2 a))))))))(defstruct surface  color)(defparameter *world* nil)
(defconstant eye (make-point :x 0 :y 0 :z 200))(defun tracer (pathname &optional (res 1))(with-open-file (p pathname :direction :output)(format p "P2 ~A ~A 255" (* res 100) (* res 100))(let ((inc (/ res)))(do ((y -50 (+ y inc)))((< (- 50 y) inc))(do ((x -50 (+ x inc)))((< (- 50 x) inc))(print (color-at x y) p))))))(defun color-at (x y)(multiple-value-bind (xr yr zr)(unit-vector (- x (x eye))(- y (y eye))(- 0 (z eye)))(round (* (sendray eye xr yr zr) 255))))(defun sendray (pt xr yr zr)(multiple-value-bind (s int) (first-hit pt xr yr zr)(if s(* (lambert s int xr yr zr) (surface-color s))0)))(defun first-hit (pt xr yr zr)(let (surface hit dist)(dolist (s *world*)(let ((h (intersect s pt xr yr zr)))(when h(let ((d (distance h pt)))(when (or (null dist) (< d dist))(setf surface s hit h dist d))))))(values surface hit)))(defun lambert (s int xr yr zr)(multiple-value-bind (xn yn zn) (normal s int)(max 0 (+ (* xr xn) (* yr yn) (* zr zn)))))(defstruct (sphere (:include surface))radius center)(defun defsphere (x y z r c)(let ((s (make-sphere:radius r:center (make-point :x x :y y :z z):color  c)))(push s *world*)s))(defun intersect (s pt xr yr zr)(funcall (typecase s (sphere #'sphere-intersect))s pt xr yr zr))(defun sphere-intersect (s pt xr yr zr)(let* ((c (sphere-center s))(n (minroot (+ (sq xr) (sq yr) (sq zr))(* 2 (+ (* (- (x pt) (x c)) xr)(* (- (y pt) (y c)) yr)(* (- (z pt) (z c)) zr)))(+ (sq (- (x pt) (x c)))(sq (- (y pt) (y c)))(sq (- (z pt) (z c)))(- (sq (sphere-radius s)))))))(if n(make-point :x  (+ (x pt) (* n xr)):y  (+ (y pt) (* n yr)):z  (+ (z pt) (* n zr))))))(defun normal (s pt)(funcall (typecase s (sphere #'sphere-normal))s pt))(defun sphere-normal (s pt)(let ((c (sphere-center s)))(unit-vector (- (x c) (x pt))(- (y c) (y pt))(- (z c) (z pt)))))(defun ray-test (&optional (res 1))(setf *world* nil)(defsphere 0 -300 -1200 200 .8)(defsphere -80 -150 -1200 200 .7)(defsphere 70 -100 -1200 200 .9)(do ((x -2 (1+ x)))((> x 2))(do ((z 2 (1+ z)))((> z 7))(defsphere (* x 200) 300 (* z -400) 40 .75)))(tracer (make-pathname :name "spheres.pgm") res)); *** mac ***(defmacro nil! (x)`(setf ,x nil))(defmacro while (test &rest body)`(do ()((not ,test)),@body))(defun quicksort (vec l r)(let ((i l)(j r)(p (svref vec (round (+ l r) 2))))    ; 1(while (<= i j)                           ; 2(while (< (svref vec i) p) (incf i))(while (> (svref vec j) p) (decf j))(when (<= i j)(rotatef (svref vec i) (svref vec j))(incf i)(decf j)))(if (> (- j l) 1) (quicksort vec l j))    ; 3(if (> (- r i) 1) (quicksort vec i r)))vec)(defmacro ntimes (n &rest body)(let ((g (gensym))(h (gensym)))`(let ((,h ,n))(do ((,g 0 (+ ,g 1)))((>= ,g ,h)),@body))))(define-modify-macro append1f (val)(lambda (lst val) (append lst (list val))))(defmacro for (var start stop &body body)(let ((gstop (gensym)))`(do ((,var ,start (1+ ,var))(,gstop ,stop))((> ,var ,gstop)),@body)))(defmacro in (obj &rest choices)(let ((insym (gensym)))`(let ((,insym ,obj))(or ,@(mapcar #'(lambda (c) `(eql ,insym ,c))choices)))))(defmacro random-choice (&rest exprs)`(case (random ,(length exprs)),@(let ((key -1))(mapcar #'(lambda (expr)`(,(incf key) ,expr))exprs))))(defmacro avg (&rest args)`(/ (+ ,@args) ,(length args)))(defmacro with-gensyms (syms &body body)`(let ,(mapcar #'(lambda (s)`(,s (gensym)))syms),@body))(defmacro aif (test then &optional else)`(let ((it ,test))(if it ,then ,else))); *** mod ***(defun make-queue () (cons nil nil))(defun enqueue (obj q)(if (null (car q))(setf (cdr q) (setf (car q) (list obj)))(setf (cdr (cdr q)) (list obj)(cdr q) (cdr (cdr q))))(car q))(defun dequeue (q)(pop (car q)))(defun mappend (fn &rest lsts)(apply #'append (apply #'mapcar fn lsts)))(defun bst-insert! (obj bst <)(if (null bst)(make-node :elt obj)(progn (bsti obj bst <)bst)))(defun bsti (obj bst <)(let ((elt (node-elt bst)))(if (eql obj elt)bst(if (funcall < obj elt)(let ((l (node-l bst)))(if l(bsti obj l <)(setf (node-l bst)(make-node :elt obj))))(let ((r (node-r bst)))(if r(bsti obj r <)(setf (node-r bst)(make-node :elt obj)))))))); >>> Replaces bst-delete from book, which was broken.(defun bst-delete (obj bst <)(if (null bst)nil(if (eql obj (node-elt bst))(del-root bst)(progn(if (funcall < obj (node-elt bst))(setf (node-l bst) (bst-delete obj (node-l bst) <))(setf (node-r bst) (bst-delete obj (node-r bst) <)))bst))))(defun del-root (bst)(let ((l (node-l bst)) (r (node-r bst)))(cond ((null l) r)((null r) l)(t        (if (zerop (random 2))(cutnext r bst nil)(cutprev l bst nil))))))(defun cutnext (bst root prev)(if (node-l bst)(cutnext (node-l bst) root bst)(if prev(progn(setf (node-elt root) (node-elt bst)(node-l prev)   (node-r bst))root)(progn(setf (node-l bst)    (node-l root))bst))))(defun cutprev (bst root prev)(if (node-r bst)(cutprev (node-r bst) root bst)(if prev(progn(setf (node-elt root) (node-elt bst)(node-r prev)   (node-l bst))root)(progn(setf (node-r bst)    (node-r root))bst))))(defun replace-node (old new)(setf (node-elt old) (node-elt new)(node-l   old) (node-l   new)(node-r   old) (node-r   new)))(defun cutmin (bst par dir)(if (node-l bst)(cutmin (node-l bst) bst :l)(progn(set-par par dir (node-r bst))(node-elt bst))))(defun cutmax (bst par dir)(if (node-r bst)(cutmax (node-r bst) bst :r)(progn(set-par par dir (node-l bst))(node-elt bst))))(defun set-par (par dir val)(case dir(:l (setf (node-l par) val))(:r (setf (node-r par) val))))(defstruct (dl (:print-function print-dl))prev data next)(defun print-dl (dl stream depth)(declare (ignore depth))(format stream "#<DL ~A>" (dl->list dl)))(defun dl->list (lst)(if (dl-p lst)(cons (dl-data lst) (dl->list (dl-next lst)))lst))(defun dl-insert (x lst)(let ((elt (make-dl :data x :next lst)))(when (dl-p lst)(if (dl-prev lst)(setf (dl-next (dl-prev lst)) elt(dl-prev elt) (dl-prev lst)))(setf (dl-prev lst) elt))elt))(defun dl-list (&rest args)(reduce #'dl-insert args:from-end t :initial-value nil))(defun dl-remove (lst)(if (dl-prev lst)(setf (dl-next (dl-prev lst)) (dl-next lst)))(if (dl-next lst)(setf (dl-prev (dl-next lst)) (dl-prev lst)))(dl-next lst))(defun circular (lst)(setf (cdr (last lst)) lst)); *** speed ***(defun length/tr (lst)(labels ((len (lst acc)(if (null lst)acc(len (cdr lst) (1+ acc)))))(len lst 0)))(setf a (make-array '(1000 1000):element-type 'single-float:initial-element 1.0s0))(defun sum-elts (a)(declare (type (simple-array single-float (1000 1000))a))(let ((sum 0.0s0))(declare (type single-float sum))(dotimes (r 1000)(dotimes (c 1000)(incf sum (aref a r c))))sum))(defconstant dict (make-array 25000 :fill-pointer 0))(defun read-words (from)(setf (fill-pointer dict) 0)(with-open-file (in from :direction :input)(do ((w (read-line in nil :eof)(read-line in nil :eof)))((eql w :eof))(vector-push w dict))))(defun xform (fn seq) (map-into seq fn seq))(defun write-words (to)(with-open-file (out to :direction :output:if-exists :supersede)(map nil #'(lambda (x)(fresh-line out)(princ x out))(xform #'nreverse(sort (xform #'nreverse dict)#'string<)))))(defparameter *harbor* nil)(defstruct shipname flag tons)(defun enter (n f d)(push (make-ship :name n :flag f :tons d)*harbor*))(defun find-ship (n)(find n *harbor* :key #'ship-name))(defun leave (n)(setf *harbor*(delete (find-ship n) *harbor*)))(defconstant pool (make-array 1000 :fill-pointer t))(dotimes (i 1000)(setf (aref pool i) (make-ship)))(defconstant harbor (make-hash-table :size 1100:test #'eq))(defun enter (n f d)(let ((s (if (plusp (length pool))(vector-pop pool)(make-ship))))(setf (ship-name s)        n(ship-flag s)        f(ship-tons s)        d(gethash n harbor) s)))(defun find-ship (n) (gethash n harbor))(defun leave (n)(let ((s (gethash n harbor)))(remhash n harbor)(vector-push s pool))); *** web ***(defmacro as (tag content)`(format t "<~(~A~)>~A</~(~A~)>"',tag ,content ',tag))(defmacro with (tag &rest body)`(progn(format t "~&<~(~A~)>~%" ',tag),@body(format t "~&</~(~A~)>~%" ',tag)))(defun brs (&optional (n 1))(fresh-line)(dotimes (i n)(princ "<br>"))(terpri))(defun html-file (base)(format nil "~(~A~).html" base))(defmacro page (name title &rest body)(let ((ti (gensym)))`(with-open-file (*standard-output*(html-file ,name):direction :output:if-exists :supersede)(let ((,ti ,title))(as title ,ti)(with center(as h2 (string-upcase ,ti)))(brs 3),@body))))(defmacro with-link (dest &rest body)`(progn(format t "<a href=\"~A\">" (html-file ,dest)),@body(princ "</a>")))(defun link-item (dest text)(princ "<li>")(with-link dest(princ text)))(defun button (dest text)(princ "[ ")(with-link dest(princ text))(format t " ]~%"))(defun map3 (fn lst)(labels ((rec (curr prev next left)(funcall fn curr prev next)(when left(rec (car left)curr(cadr left)(cdr left)))))(when lst(rec (car lst) nil (cadr lst) (cdr lst)))))(defparameter *sections* nil)(defstruct itemid title text)(defstruct sectionid title items)(defmacro defitem (id title text)`(setf ,id(make-item :id     ',id:title  ,title:text   ,text)))(defmacro defsection (id title &rest items)`(setf ,id(make-section :id    ',id:title ,title:items (list ,@items))))(defun defsite (&rest sections)(setf *sections* sections))(defconstant contents "contents")
(defconstant index    "index")(defun gen-contents (&optional (sections *sections*))(page contents contents(with ol(dolist (s sections)(link-item (section-id s) (section-title s))(brs 2))(link-item index (string-capitalize index)))))(defun gen-index (&optional (sections *sections*))(page index index(with ol(dolist (i (all-items sections))(link-item (item-id i) (item-title i))(brs 2)))))(defun all-items (sections)(let ((is nil))(dolist (s sections)(dolist (i (section-items s))(setf is (merge 'list (list i) is #'title<))))is))(defun title< (x y)(string-lessp (item-title x) (item-title y)))(defun gen-site ()(map3 #'gen-section *sections*)(gen-contents)(gen-index))(defun gen-section (sect <sect sect>)(page (section-id sect) (section-title sect)(with ol(map3 #'(lambda (item <item item>)(link-item (item-id item)(item-title item))(brs 2)(gen-item sect item <item item>))(section-items sect)))(brs 3)(gen-move-buttons (if <sect (section-id <sect))contents(if sect> (section-id sect>)))))(defun gen-item (sect item <item item>)(page (item-id item) (item-title item)(princ (item-text item))(brs 3)(gen-move-buttons (if <item (item-id <item))(section-id sect)(if item> (item-id item>)))))(defun gen-move-buttons (back up forward)(if back (button back "Back"))(if up (button up "Up"))(if forward (button forward "Forward"))); *** inf ***(defun match (x y &optional binds)(cond((eql x y) (values binds t))((assoc x binds) (match (binding x binds) y binds))((assoc y binds) (match x (binding y binds) binds))((var? x) (values (cons (cons x y) binds) t))((var? y) (values (cons (cons y x) binds) t))(t(when (and (consp x) (consp y))(multiple-value-bind (b2 yes)(match (car x) (car y) binds)(and yes (match (cdr x) (cdr y) b2)))))))(defun var? (x)(and (symbolp x)(eql (char (symbol-name x) 0) #\?)))(defun binding (x binds)(let ((b (assoc x binds)))(if b(or (binding (cdr b) binds)(cdr b)))))(defvar *rules* (make-hash-table))(defmacro <- (con &optional ant)`(length (push (cons (cdr ',con) ',ant)(gethash (car ',con) *rules*))))(defun prove (expr &optional binds)(case (car expr)(and (prove-and (reverse (cdr expr)) binds))(or  (prove-or (cdr expr) binds))(not (prove-not (cadr expr) binds))(t   (prove-simple (car expr) (cdr expr) binds))))(defun prove-simple (pred args binds)(mapcan #'(lambda (r)(multiple-value-bind (b2 yes)(match args (car r)binds)(when yes(if (cdr r)(prove (cdr r) b2)(list b2)))))(mapcar #'change-vars(gethash pred *rules*))))(defun change-vars (r)(sublis (mapcar #'(lambda (v) (cons v (gensym "?")))(vars-in r))r))(defun vars-in (expr)(if (atom expr)(if (var? expr) (list expr))(union (vars-in (car expr))(vars-in (cdr expr)))))(defun prove-and (clauses binds)(if (null clauses)(list binds)(mapcan #'(lambda (b)(prove (car clauses) b))(prove-and (cdr clauses) binds))))(defun prove-or (clauses binds)(mapcan #'(lambda (c) (prove c binds))clauses))(defun prove-not (clause binds)(unless (prove clause binds)(list binds)))(defmacro with-answer (query &body body)(let ((binds (gensym)))`(dolist (,binds (prove ',query))(let ,(mapcar #'(lambda (v)`(,v (binding ',v ,binds)))(vars-in query)),@body)))); *** ob ***(defmacro parents (v) `(svref ,v 0))
(defmacro layout (v) `(the simple-vector (svref ,v 1)))
(defmacro preclist (v) `(svref ,v 2))(defmacro class (&optional parents &rest props)`(class-fn (list ,@parents) ',props))(defun class-fn (parents props)(let* ((all (union (inherit-props parents) props))(obj (make-array (+ (length all) 3):initial-element :nil)))(setf (parents obj)  parents(layout obj)   (coerce all 'simple-vector)(preclist obj) (precedence obj))obj))(defun inherit-props (classes)(delete-duplicates(mapcan #'(lambda (c)(nconc (coerce (layout c) 'list)(inherit-props (parents c))))classes)))(defun precedence (obj)(labels ((traverse (x)(cons x(mapcan #'traverse (parents x)))))(delete-duplicates (traverse obj))))(defun inst (parent)(let ((obj (copy-seq parent)))(setf (parents obj)  parent(preclist obj) nil)(fill obj :nil :start 3)obj));(declaim (inline lookup (setf lookup)))(defun rget (prop obj next?)(let ((prec (preclist obj)))(if prec(dolist (c (if next? (cdr prec) prec) :nil)(let ((val (lookup prop c)))(unless (eq val :nil) (return val))))(let ((val (lookup prop obj)))(if (eq val :nil)(rget prop (parents obj) nil)val)))))(defun lookup (prop obj)(let ((off (position prop (layout obj) :test #'eq)))(if off (svref obj (+ off 3)) :nil)))(defun (setf lookup) (val prop obj)(let ((off (position prop (layout obj) :test #'eq)))(if off(setf (svref obj (+ off 3)) val)(error "Can't set ~A of ~A." val obj))))(declaim (inline run-methods))(defmacro defprop (name &optional meth?)`(progn(defun ,name (obj &rest args),(if meth?`(run-methods obj ',name args)`(rget ',name obj nil)))(defun (setf ,name) (val obj)(setf (lookup ',name obj) val))))(defun run-methods (obj name args)(let ((meth (rget name obj nil)))(if (not (eq meth :nil))(apply meth obj args)(error "No ~A method for ~A." name obj))))(defmacro defmeth (name obj parms &rest body)(let ((gobj (gensym)))`(let ((,gobj ,obj))(defprop ,name t)(setf (lookup ',name ,gobj)(labels ((next () (rget ,gobj ',name t)))#'(lambda ,parms ,@body)))))); *** adv ***(defun copy-file (from to)(with-open-file (in from :direction :input:element-type 'unsigned-byte)(with-open-file (out to :direction :output:element-type 'unsigned-byte)(do ((i (read-byte in nil -1)(read-byte in nil -1)))((minusp i))(declare (fixnum i))(write-byte i out)))))(set-dispatch-macro-character #\# #\?#'(lambda (stream char1 char2)(list 'quote(let ((lst nil))(dotimes (i (+ (read stream t nil t) 1))(push i lst))(nreverse lst)))))(set-macro-character #\} (get-macro-character #\)))(set-dispatch-macro-character #\# #\{#'(lambda (stream char1 char2)(let ((accum nil)(pair (read-delimited-list #\} stream t)))(do ((i (car pair) (+ i 1)))((> i (cadr pair))(list 'quote (nreverse accum)))(push i accum)))))(defun even/odd (ns)(loop for n in nsif (evenp n)collect n into evenselse collect n into oddsfinally (return (values evens odds))))(defun user-input (prompt)(format t prompt)(let ((str (read-line)))(or (ignore-errors (read-from-string str))nil))); *** notes ***(defun float-limits ()(dolist (m '(most least))(dolist (s '(positive negative))(dolist (f '(short single double long))(let ((n (intern (string-upcase(format nil "~A-~A-~A-float"m  s  f)))))(format t "~30A ~A~%" n (symbol-value n)))))))(defmacro bst-push (obj bst <)(multiple-value-bind (vars forms var set access)(get-setf-expansion bst)(let ((g (gensym)))`(let* ((,g ,obj),@(mapcar #'list vars forms)(,(car var) (bst-insert! ,g ,access ,<))),set))))(defmacro with-type (type expr)`(the ,type ,(if (atom expr)expr(expand-call type (binarize expr)))))(defun expand-call (type expr)`(,(car expr) ,@(mapcar #'(lambda (a)`(with-type ,type ,a))(cdr expr))))(defun binarize (expr)(if (and (nthcdr 3 expr)(member (car expr) '(+ - * /)))(destructuring-bind (op a1 a2 . rest) expr(binarize `(,op (,op ,a1 ,a2) ,@rest)))expr))(defmacro with-slotref ((name prop class) &rest body)(let ((g (gensym)))`(let ((,g (+ 3 (position ,prop (layout ,class):test #'eq))))(macrolet ((,name (obj) `(svref ,obj ,',g))),@body))))(defun eval2 (expr)(case (and (consp expr) (car expr))(comma (error "unmatched comma"))(bq    (eval-bq (second expr) 1))(t     (eval expr))))(defun eval-bq (expr n)(cond ((atom expr)expr)((eql (car expr) 'comma)(if (= n 1)(eval2 (second expr))(list 'comma (eval-bq (second expr)(1- n)))))((eql (car expr) 'bq)(list 'bq (eval-bq (second expr) (1+ n))))(t(cons (eval-bq (car expr) n)(eval-bq (cdr expr) n))))); *** lib ***(defun -abs (n)(if (typep n 'complex)(sqrt (+ (expt (realpart n) 2) (expt (imagpart n) 2)))(if (< n 0) (- n) n)))(defun -adjoin (obj lst &rest args)(if (apply #'member obj lst args) lst (cons obj lst)))
(defmacro -and (&rest args)(cond ((null args) t)((cdr args)  `(if ,(car args) (-and ,@(cdr args))))(t           (car args))))(defun -append (&optional first &rest rest)(if (null rest)first(nconc (copy-list first) (apply #'-append rest))))(defun -atom (x) (not (consp x)))(defun -butlast (lst &optional (n 1))(nreverse (nthcdr n (reverse lst))))(defun -cadr (x) (car (cdr x)))(defmacro -case (arg &rest clauses)(let ((g (gensym)))`(let ((,g ,arg))(cond ,@(mapcar #'(lambda (cl)(let ((k (car cl)))`(,(cond ((member k '(t otherwise))t)((consp k)`(member ,g ',k))(t `(eql ,g ',k)))(progn ,@(cdr cl)))))clauses)))))(defun -cddr (x) (cdr (cdr x)))(defun -complement (fn)#'(lambda (&rest args) (not (apply fn args))))(defmacro -cond (&rest args)(if (null args)nil(let ((clause (car args)))(if (cdr clause)`(if ,(car clause)(progn ,@(cdr clause))(-cond ,@(cdr args)))`(or ,(car clause)(-cond ,@(cdr args)))))))(defun -consp (x) (typep x 'cons))(defun -constantly (x) #'(lambda (&rest args) x))(defun -copy-list (lst)(labels ((cl (x)(if (atom x)x(cons (car x)(cl (cdr x))))))(cons (car lst)(cl (cdr lst)))))(defun -copy-tree (tr)(if (atom tr)tr(cons (-copy-tree (car tr))(-copy-tree (cdr tr)))))(defmacro -defun (name parms &rest body)(multiple-value-bind (dec doc bod) (analyze-body body)`(progn(setf (fdefinition ',name)#'(lambda ,parms,@dec(block ,(if (atom name) name (second name)),@bod))(documentation ',name 'function),doc)',name)))(defun analyze-body (body &optional dec doc)(let ((expr (car body)))(cond ((and (consp expr) (eq (car expr) 'declare))(analyze-body (cdr body) (cons expr dec) doc))((and (stringp expr) (not doc) (cdr body))(if dec(values dec expr (cdr body))(analyze-body (cdr body) dec expr)))(t (values dec doc body))))); This definition is not strictly correct; see let.(defmacro -do (binds (test &rest result) &rest body)(let ((fn (gensym)))`(block nil(labels ((,fn ,(mapcar #'car binds)(cond (,test ,@result)(t (tagbody ,@body)(,fn ,@(mapcar #'third binds))))))(,fn ,@(mapcar #'second binds))))))(defmacro -dolist ((var lst &optional result) &rest body)(let ((g (gensym)))`(do ((,g ,lst (cdr ,g)))((atom ,g) (let ((,var nil)) ,result))(let ((,var (car ,g))),@body))))(defun -eql (x y)(typecase x(character (and (typep y 'character) (char= x y)))(number    (and (eq (type-of x) (type-of y))(= x y)))(t         (eq x y))))(defun -evenp (x)(typecase x(integer (= 0 (mod x 2)))(t       (error "non-integer argument"))))(defun -funcall (fn &rest args) (apply fn args))(defun -identity (x) x); This definition is not strictly correct: the expression
; (let ((&key 1) (&optional 2))) is legal, but its expansion
; is not.(defmacro -let (parms &rest body)`((lambda ,(mapcar #'(lambda (x)(if (atom x) x (car x)))parms),@body),@(mapcar #'(lambda (x)(if (atom x) nil (cadr x)))parms)))
(defun -list (&rest elts) (copy-list elts))(defun -listp (x) (or (consp x) (null x)))(defun -mapcan (fn &rest lsts)(apply #'nconc (apply #'mapcar fn lsts)))(defun -mapcar (fn &rest lsts)(cond ((member nil lsts) nil)((null (cdr lsts))(let ((lst (car lsts)))(cons (funcall fn (car lst))(-mapcar fn (cdr lst)))))(t(cons (apply fn (-mapcar #'car lsts))(apply #'-mapcar fn(-mapcar #'cdr lsts))))))(defun -member (x lst &key test test-not key)(let ((fn (or test(if test-not(complement test-not))#'eql)))(member-if #'(lambda (y)(funcall fn x y))lst:key key)))(defun -member-if (fn lst &key (key #'identity))(cond ((atom lst) nil)((funcall fn (funcall key (car lst))) lst)(t (-member-if fn (cdr lst) :key key))))(defun -mod (n m)(nth-value 1 (floor n m)))(defun -nconc (&optional lst &rest rest)(if rest(let ((rest-conc (apply #'-nconc rest)))(if (consp lst)(progn (setf (cdr (last lst)) rest-conc)lst)rest-conc))lst))(defun -not (x) (eq x nil))
(defun -nreverse (seq)(labels ((nrl (lst)(let ((prev nil))(do ()((null lst) prev)(psetf (cdr lst) prevprev      lstlst       (cdr lst)))))(nrv (vec)(let* ((len (length vec))(ilimit (truncate (/ len 2))))(do ((i 0 (1+ i))(j (1- len) (1- j)))((>= i ilimit) vec)(rotatef (aref vec i) (aref vec j))))))(if (typep seq 'vector)(nrv seq)(nrl seq))))(defun -null (x) (eq x nil))(defmacro -or (&optional first &rest rest)(if (null rest)first(let ((g (gensym)))`(let ((,g ,first))(if ,g,g(-or ,@rest)))))); Not in CL, but needed in several definitions here.(defun pair (lst)(if (null lst)nil(cons (cons (car lst) (cadr lst))(pair (cddr lst)))))(defun -pairlis (keys vals &optional alist)(unless (= (length keys) (length vals))(error "mismatched lengths"))(nconc (mapcar #'cons keys vals) alist))(defmacro -pop (place)(multiple-value-bind (vars forms var set access)(get-setf-expansion place)(let ((g (gensym)))`(let* (,@(mapcar #'list vars forms)(,g ,access)(,(car var) (cdr ,g)))(prog1 (car ,g),set)))))(defmacro -prog1 (arg1 &rest args)(let ((g (gensym)))`(let ((,g ,arg1)),@args,g)))(defmacro -prog2 (arg1 arg2 &rest args)(let ((g (gensym)))`(let ((,g (progn ,arg1 ,arg2))),@args,g)))(defmacro -progn (&rest args) `(let nil ,@args))(defmacro -psetf (&rest args)(unless (evenp (length args))(error "odd number of arguments"))(let* ((pairs (pair args))(syms (mapcar #'(lambda (x) (gensym))pairs)))`(let ,(mapcar #'listsyms(mapcar #'cdr pairs))(setf ,@(mapcan #'list(mapcar #'car pairs)syms)))))(defmacro -push (obj place)(multiple-value-bind (vars forms var set access)(get-setf-expansion place)(let ((g (gensym)))`(let* ((,g ,obj),@(mapcar #'list vars forms)(,(car var) (cons ,g ,access))),set))))(defun -rem (n m)(nth-value 1 (truncate n m)))(defmacro -rotatef (&rest args)`(psetf ,@(mapcan #'listargs(append (cdr args)(list (car args))))))(defun -second (x) (cadr x))(defmacro -setf (&rest args)(if (null args)nil`(setf2 ,@args)))(defmacro setf2 (place val &rest args)(multiple-value-bind (vars forms var set)(get-setf-expansion place)`(progn(let* (,@(mapcar #'list vars forms)(,(car var) ,val)),set),@(if args `((setf2 ,@args)) nil))))(defun -signum (n)(if (zerop n) 0 (/ n (abs n))))(defun -stringp (x) (typep x 'string))(defun -tailp (x y)(or (eql x y)(and (consp y) (-tailp x (cdr y)))))(defun -third (x) (car (cdr (cdr x))))(defun -truncate (n &optional (d 1))(if (> n 0) (floor n d) (ceiling n d)))(defmacro -typecase (arg &rest clauses)(let ((g (gensym)))`(let ((,g ,arg))(cond ,@(mapcar #'(lambda (cl)`((typep ,g ',(car cl))(progn ,@(cdr cl))))clauses)))))
(defmacro -unless (arg &rest body)`(if (not ,arg)(progn ,@body)))(defmacro -when (arg &rest body)`(if ,arg (progn ,@body)))(defun -1+ (x) (+ x 1))(defun -1- (x) (- x 1))(defun ->= (first &rest rest)(or (null rest)(and (or (> first (car rest)) (= first (car rest)))(apply #'->= rest))))

Lisp 学习资源集锦相关推荐

  1. 史上最全的Angular.js 的学习资源

    Angular.js 的一些学习资源 基础 官方: http://docs.angularjs.org angularjs官方网站已被墙,可看 http://www.ngnice.com/: 官方zi ...

  2. 机器学习入门学习资源

    机器学习入门学习资源 [转载请注明出处]http://blog.csdn.net/guyuealian/article/details/51471085 这是一篇很难写的文章,因为我希望这篇文章能对学 ...

  3. Android 学习资源收集

    在开始讲述之前,你应该先看一下世界各地的开发人员是如何推荐的,他们自己学习Android时又是用的什么资源.这里我们将Quora和Reddit上针对Android应用开发学习所推荐的优秀资源做了快速总 ...

  4. NI无线通信与射频技术学习资源汇总

    NI公司无线与射频学习资源包文件共150MB,超过100多个学习资源文件. 软件无线电USRP 2小时上手教程 http://ni.mwrf.net/down/2015/266.html LabVIE ...

  5. 因特网上的英语学习资源

    毫无疑问计算机网络--因特网是外语学习的有用工具,通过环球网和电子邮件我们能获得大量英语学习和教学的新信息和许多网上交流机会,为了帮助英语爱好者通过因特网学习英语,笔者在网上收集了其中的一部分英语学习 ...

  6. Common Lisp学习之一:初识CL的语法与语义

    Lisp是一类语言的统称,指那些使用前缀表达式和S表达式进行代码编写和编译的语言.此类语言有CL,Scheme,Racket,Clojure等.Lisp语言和其他语言相比,其优势在于无比强大的抽象能力 ...

  7. 英语学习资源下载大全 一网打尽

    adventuretv,提供视频资料,内容多是各地的风土人情,很不错. http://www.adventuretv.com/ 纽约时报,网上看新闻的好地方 http://www.nytimes.co ...

  8. (转)英文学习资源站点

    http://www.oeol.net/oeol/gb/index.asp "牛津英语在线" ( Oxford English On line ) 一个由牛津大学的毕业生们创建的英 ...

  9. 这些Python免费学习资源不可错过,适合有图形化编程基础需要提升能力的你!...

    刚刚过去的暑假里,浙江.厦门.武汉等多地教育局通知,将在中小学生新学期课本中加入Python编程内容. 之前了解过少儿编程的家长,肯定都对Scratch.Python非常熟悉了,这两种编程语言都非常友 ...

最新文章

  1. thin还是thick?虚拟磁盘格式的选择题
  2. 全球农企对话国际农民丰收节贸易会·万祥军:拜耳谋定领先
  3. 第二篇、通过蓝牙连接外设
  4. iOS之深入解析Block的使用和外部变量捕获
  5. CentOS7卸载并安装mysql教程
  6. 记录对String.format(Formatter().format())方法的总结
  7. 吴恩达深度学习1.2练习_Neural Networks and Deep Learning
  8. Java运行时,指定程序文件的编码
  9. 安装PdaNet以连接Android设备
  10. 【Linux】rpm包是什么
  11. SlidingBall滚动效果集成问题解决经验
  12. 优秀博士生和普通博士生差距能有多大?
  13. 基于VirtualBox虚拟机安装Ubuntu图文教程
  14. 使用软碟通做启动盘给电脑装系统时如何分区
  15. 用c++两个分数相加并且化简成最简形式,通过类来完成。思想是:求出两个数的最大公约数用来化简和求最大公倍数,具体公式代码中见
  16. 关于Pascal和二项式系数
  17. dwm.exe_什么是桌面窗口管理器(dwm.exe),为什么运行?
  18. K8s学习之yum安装
  19. KODI软件的下载与简单使用(开启倍速到1.1,1.2,1.3等等或整数倍速)
  20. FreeRTOS学习六(软件定时器)

热门文章

  1. linux2.6.32 layer7,在Debian 上编译内核2.6.26.3加入Layer7模块
  2. 可信数据服务-区块链外包
  3. pytorch实现图像分类,训练集准确率很高,测试集准确率总是很低
  4. 微信小程序开发与app开发的十大区别
  5. 人人学IoT---------第六章学习笔记
  6. 零前端基础硬刚《象棋》- 持续更新
  7. 怎样从浏览器保存html文件在哪里,电脑浏览器收藏夹保存在哪里
  8. Mybatis-01-概念理解
  9. 目如秋水黛眉低——游戏保卫森林(Python实现)
  10. 面试真题总结:Faster Rcnn,目标检测,卷积,梯度消失,Adam算法