際際滷

際際滷Share a Scribd company logo
( Lisp )
@ Lisp
 Lisp螳 覘 覩誤 蟇一?
 AI語?
 蠍磯 伎螻, 蟯瑚 襷 語?
 轟?
Lisp螳 覘 覩誤 蟇一?
 企 蠍一 : LISt Processing
 企  Linked List( 郁屋
襴ろ)螳 譯朱 襭蟲譟.
AI 語?
 John McCarthy
 Lisp 覯讌 "譟 襷れ拘
 (1927 9 4 ~ 2011 10 24)
 1956 ろ碁┯  豌朱 瑚概讌(Artificial
Intelligence)企朱 企ゼ 谿曙
 1958 Lisp 螳覦
 1960 朱 "Recursive Functions of Symbolic Expressions and
Their Computation by Machine, Part I
 1971 襷 . 瑚概讌レ  郁規 語
Lisp Machine in MITs Museum
蠍磯 伎螻, 蟯瑚 襷 語?
  蠍磯 : + 1 2
 譴 蠍磯 : 1 + 2
  蠍磯 : 1 2 +
 (1 + 2) * 3 => * + 1 2 3 => (* (+ 1 2) 3)
蟯
 豌 蟇磯螳 
 Html, Xml覲企 覲願鍵 暑!
 貊 一危磯ゼ 覓苦伎朱 覈
轟?
 From Wikipedia
 れ : , 谿, reflective, meta
  : Dynamic, strong
  : (蟆) S-expression
 襷ろ襦
 螳觜讌貊
 誤壱襴一伎 貉危朱
 襦蠏碁覦 語?
 First-class
  螳豌企 朱 焔  朱, 語
襦 蠍郁碓 覦  
 企 危(side effect)螳 
 But!, pure functional .
Atom
&
Expression
@ REPL
 Read Eval Print Loop
 Interactive shell企手 覿襴蠍磯 .
(defun game-repl ()
(let ((cmd (game-read)))
(unless (eq (car cmd) 'quit)
(game-print (game-eval cmd))
(game-repl))))
@ Atom
 覲
 
 谿, 蟇一 蠏碁Μ螻 NIL
覲
CL-USER> a
The variable A is unbound.
CL-USER> (defvar a 1)
A
CL-USER> a
1
CL-USER> (list a)
(1)
CL-USER> :a
:A

 一
 1234
 
 123.4
 覿
 123/4 = (/ 123 4)
 覲旧
 #C(1 2) = (complex 1 2) = 1 + 2i

CL-USER> (+ 5/9 3/4)
47/36
CL-USER> (* 2 (+ #c(10 5) 4)) ;; 2 * ( (10 + 5i) +
4)
#C(28 10)
CL-USER> (expt (expt (expt (expt 10 10) 10) 10)
10)
100000000000000000000000000000000000
谿瑚骸 蟇一
 谿 : T
 蟇一 : NIL
 , Common Lisp, NIL螻 () 狩 蟆朱
螳譯狩.
 襷豺 C  if( x ) x螳 0企 蟇一企手 
 蟆螻 螳
 , 螳螳 蟲(Clojure, Scheme) 谿, 蟇
讌 譟郁唄 るゼ  朱 譯殊.
NIL
CL-USER> nil
NIL
CL-USER> ()
NIL
CL-USER> (list)
NIL
CL-USER> (list nil)
(NIL)
@ Expression
 S-expression ?
 Cons cell?
 car, cdr ?
 Cons cell & car, cdr
S-expression ?
 S-expression
 (Symbolic-expression, sexpr)
 Atom :  | 覲.
 蠍一 覲殊 覲企企 一危磯  覓
讌.
 Expression
 (x . y) 螳 (form)襯  . (蠍一 x, y
 s-exression)
Cons cell ?
 constructs memory objects which hold
two values or pointers to values.
(setf x '(a (r t) b))
car, cdr ?
 car, cdr 企 覿 蟾
 "IBM 704" lisp襯 蟲, 轟 "IBM 704" 
 讌ろ一 企 car, cdr伎.
 ,企 first rest蟆 朱 caar, cadr, cdadr 譴豌れ
襯 豌危蠍一 覓企Μ螳 .
[15 Address][15 Decrement][3 Prefix][3 Tag]
car (Contents of the Address part of Register number)
cdr (Contents of the Decrement part of Register number)
cpr (Contents of the Prefix part of Register number)
ctr (Contents of the Tag part of Register number)
Cons cell & car, cdr
CL-USER> (cons 1 2)
(1 . 2)
CL-USER> (car '(1 . 2))
1
CL-USER> (cdr '(1 . 2))
2
CL-USER> (cons 1 nil)
(1)
CL-USER> (cons 1 (cons 2 (cons 3 nil)))
(1 2 3)
CL-USER> (list 1 2 3)
(1 2 3)
Lambda
@ Lambda
 lambda
 funcall & eval
 defun
 (了 -, lambda -)  , 
 , 蠏 襯 朱 
蠍   豌願企
lambda
CL-USER> (lambda (x) (+ x 10))
#<FUNCTION (LAMBDA (X)) {2496A42D}>
CL-USER> ( (lambda (x y)
(+ (* x x) (* y y)))
5 2 )
29
funcall & eval
CL-USER> (setq a (lambda (x) (+ x 10)))
#<FUNCTION (LAMBDA (X)) {2496A42D}>
CL-USER> (funcall a 123)
133
CL-USER> (eval '(funcall a 123))
133
defun
CL-USER> (defun sum-of-1-to-n (n)
(/ (* n (1+ n)) 2))
SUM-OF-1-TO-N
CL-USER> (sum-of-1-to-n 100)
5050
???
  (funcall a 10) ??
 蠏碁 (a 10)覃 蟆 螳
 Common Lisp
 Variable螻 Funtion 企螻糾 螳れ.
 Scheme
 Variable螻 Function 企螻糾 螳.
Condition
@ Condition
 If
 when
 Unless
 Cond
if
(defun number? (n)
(if (zerop n)
:zero
(if (minusp n)
:minus
(if (plusp n)
:plus
:idk))))
when, unless
(defun number?-when (n)
(when (zerop n)
(return-from number?-when :zero))
(when (minusp n)
(return-from number?-when :minus))
(when (plusp n)
(return-from number?-when :plus))
:idk)
(defun float?-unless (n)
(unless (floatp n)
(return-from float?-unless :not-float))
:float)
cond
(defun number-what3 (n)
(cond ((minusp n) :minus)
((zerop n) :zero)
((plusp n) :plus)
(t :idk)))
Binding
Binding
 let, let*
 flet, lables
 Lexical & dynamic
Let, let*
CL-USER> (let ((x 10)
(y 20))
(+ x y))
30
CL-USER> (let* ((x 10)
(y (+ x 20)))
y)
30
flet, lables
CL-USER> (flet ((hello (x) (1- x)))
(hello 10))
9
CL-USER> (labels ((hello (x)
(if (> x 3)
(hello (1- x))
x)))
(hello 10))
3
Lexical & dynamic
(defparameter *global* 10)
(defun hello ()
(print *global*))
(let ((x *global*))
(defun hello2 ()
(print x)))
LISt Processing
@ LISt Processing
 Quote, Unquote
 Macro
 defmacro
Quote, Unquote
CL-USER> a
1
CL-USER> (quote
a)
A
CL-USER>a
A
CL-USER> (list a)
(1)
CL-USER> (a)
(A)
CL-USER> `(,a)
(1)
` 襯 譯朱,
Scheme 企ゼ Quasiquote
Common Lisp backquote 覿
襴.
CL-USER> `(1 2 ,@(list 3 4))
(1 2 3 4)
Macro
 Lisp form企 object襯 覦 貉危 蟇磯 
 貊襯 
 覓碁 豢 蠍磯 螻
 Domain-specific language 所 讌.
 壱  襷ろ襦   
 豕  譯手鍵 
 蟾螻, 螳蟆壱 貊襯 企伎
cond macro
(defmacro cond (&rest clauses)
(when clauses
(let* ((this (first clauses))
(others (rest clauses))
(test (first this))
(forms (rest this)))
`(if ,test
(progn ,@forms)
(cond ,@others)))))
cond expand
(IF (MINUSP N)
(PROGN :MINUS)
(COND ((ZEROP N) :ZERO)
((PLUSP N) :PLUS)
(T :IDK)))
(cond ((minusp n) :minus)
((zerop n) :zero)
((plusp n) :plus)
(t :idk))
DSL
@ DSL
 DSL
 loop
 format
DSL
 DSL企?
 Domain-Specific Language
 螳  貊(Intention-revealing code)
 轟 覓語襯 蟆朱  貉危 語
 External DSLs
 讌蠍 螻  語伎 碁 譟伎 DSL.
 ex) SQL, 蠏
 Graphical DSLs
 襯 蠍  覓語覲企  伎 DSL
 ex) UML
 覓語  讌襷, れ 覓語襯 願屋蠍 伎 蠏碁れ..
 Fluent interfaces
 Api襯  覦一 所鍵 ク蟆襷.
 壱讌  語伎 譯朱 .
 Internal or embeded DSLs
 讌蠍 螻  語企ゼ 蠏碁襦  DSL
loop
CL-USER> (loop for i from 1 to 10
collect i)
(1 2 3 4 5 6 7 8 9 10)
format
CL-USER> (format nil "~{~a~^, ~}
'(1 2 3 4 5))
"1, 2, 3, 4, 5"
CLOS
clos
 Common Lisp Object System
 螳豌伎レ 讌蠍 , 語願規 
蟆 , 襷ろ襦襯 伎 豈.
(defclass <POS> ()
((x :initarg :x :accessor x)
(y :initarg :y :accessor y)))
(defun new-pos (x y)
(make-instance '<POS> :x x :y y))
(defparameter p1 (new-pos 10 20))
(defmethod print-object ((pos <POS>) stream)
(with-slots (x y) pos
(format stream "#<Pos ~a, ~a>" x y)))
(defmethod rotate ((pos <POS>))
(with-slots (x y) pos
(new-pos (- y) x)))
(defclass <Rectangle> ()
((w :accessor w :initarg :w)
(h :accessor h :initarg :h)))
(defclass <Circle> ()
((r :accessor r :initarg :r)))
(defmethod area! ((rectangle <Rectangle>))
(with-slots (w h) rectangle
(* w h)))
(defmethod area! ((circle <Circle>))
(with-slots (r) circle
(* pi (expt r 2))))
(defparameter aa (make-instance '<Rectangle> :w 10 :h 20))
(defparameter bb (make-instance '<Circle> :r 10))
(area! aa)
(area! bb)
Debug
@ Debug
 step
 trace
 declare & disassamble
step
CL-USER> (step (labels ((hello (x)
(if (> x 3)
(hello (1- x))
x)))
(hello 10)))
trace
CL-USER> (defun hello (x)
(if (> x 3)
(hello (1- x))
x))
HELLO
CL-USER> (trace hello)
(HELLO)
CL-USER> (hello 5)
0: (HELLO 5)
1: (HELLO 4)
2: (HELLO 3)
2: HELLO returned 3
1: HELLO returned 3
0: HELLO returned 3
3
CL-USER> (untrace hello)
T
disassemble
(defun add1 (n)
(1+ n))
(disassemble 'add1)
; disassembly for ADD1
; 247C2D38: 840500000021 TEST AL, [#x21000000]
; 3E: 8B55FC MOV EDX, [EBP-4]
; 41: BF04000000 MOV EDI, 4
; 46: E84DD483FD CALL #x22000198
; 4B: 7302 JNB L0
; 4D: 8BE3 MOV ESP, EBX
; 4F: L0: 8BE5 MOV ESP, EBP
; 51: F8 CLC
; 52: 5D POP EBP
; 53: C3 RET
; 54: CC0A BREAK 10
; 56: 02 BYTE #X02
; 57: 18 BYTE #X18
; 58: 4F BYTE #X4F ; ECX
declare
(defun int-add1 (n)
(declare (fixnum n)
(optimize (speed 3) (safety 0) (debug 0)))
(the fixnum (1+ n)))
(disassemble 'int-add1)
; disassembly for INT-ADD1
; 2489E3E0: 840500000021 TEST AL, [#x21000000] ;
no-arg-parsing entry point
; 6: 83C204 ADD EDX, 4
; 9: 8BE5 MOV ESP, EBP
; B: F8 CLC
; C: 5D POP EBP
; D: C3 RET
Foreign Function Interface
#include <stdio.h>
int hello (int a, int b) {
return a + b;
}
gcc -shared -o test.so test
(ql:quickload :cffi)
(in-package :cl-user)
(defpackage :cffi-exam
(:use :cl :cffi))
(in-package :cffi-exam)
(define-foreign-library test.so
(t (:default "~/tmp/test")))
(use-foreign-library test.so)
(defcfun "hello" :int
(a :int)
(b :int))
(hello 1 2)
Cffi-with-gcc
Cffi-with-win32
(in-package :cl-user)
(defpackage winapi
(:use :cl :cffi))
(in-package :winapi)
(define-foreign-library user32.dll
(t (:default "user32")))
(define-foreign-library kernel32.dll
(:windows "kernel32"))
(cffi:define-foreign-library gdi32.dll
(:windows "gdi32.dll"))
(use-foreign-library user32.dll)
(use-foreign-library kernel32.dll)
(use-foreign-library gdi32.dll)
(ql:quickload :cffi)
(defctype LPCSTR :string)
(defctype HANDLE :pointer)
(defctype HWND HANDLE)
(DEFCFUN ("MessageBoxA" MessageBox) :INT
(HWND HWND)
(LPTEXT LPCSTR)
(LPCAPTION LPCSTR)
(UTYPE :UINT))
(MessageBox (null-pointer) "hello" "world" 0)
More and
More
elisp
abcl
(Lisp)
谿瑚襭
Common Lisp:
A Gentle Introduction to Symbolic Computation
Land of Lisp
The Less than Rapid prototype
"Because Lisp and rapid prototyping evolved
together, Lisp include a lot of features
specifically inteded for prototype: inefficient
but convenient features like property lists,
keyword parameters, and, for that matter, lists."
"It's important to realize, though, that Lisp is a
language for writing production software as well
as a language for writing prototypes.
- 豈 OnLisp -  : Paul Graham ( Y
Combinator 谿暑曙 )
links
 Peter Seibel's Practical Common Lisp
 Paul Graham's On Lisp
 David Lamkin's Successful Lisp
 Shriram Krishnamurthi's Programming Languages:
Application and Interpretation
 Guy Steele's Common Lisp the Language, 2nd ed.
 LispWorks HyperSpec.

More Related Content

(Lisp)

  • 2. @ Lisp Lisp螳 覘 覩誤 蟇一? AI語? 蠍磯 伎螻, 蟯瑚 襷 語? 轟?
  • 3. Lisp螳 覘 覩誤 蟇一? 企 蠍一 : LISt Processing 企 Linked List( 郁屋 襴ろ)螳 譯朱 襭蟲譟.
  • 4. AI 語? John McCarthy Lisp 覯讌 "譟 襷れ拘 (1927 9 4 ~ 2011 10 24) 1956 ろ碁┯ 豌朱 瑚概讌(Artificial Intelligence)企朱 企ゼ 谿曙 1958 Lisp 螳覦 1960 朱 "Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I 1971 襷 . 瑚概讌レ 郁規 語
  • 5. Lisp Machine in MITs Museum
  • 6. 蠍磯 伎螻, 蟯瑚 襷 語? 蠍磯 : + 1 2 譴 蠍磯 : 1 + 2 蠍磯 : 1 2 + (1 + 2) * 3 => * + 1 2 3 => (* (+ 1 2) 3)
  • 7. 蟯 豌 蟇磯螳 Html, Xml覲企 覲願鍵 暑! 貊 一危磯ゼ 覓苦伎朱 覈
  • 8. 轟? From Wikipedia れ : , 谿, reflective, meta : Dynamic, strong : (蟆) S-expression 襷ろ襦 螳觜讌貊 誤壱襴一伎 貉危朱
  • 9. 襦蠏碁覦 語? First-class 螳豌企 朱 焔 朱, 語 襦 蠍郁碓 覦 企 危(side effect)螳 But!, pure functional .
  • 11. @ REPL Read Eval Print Loop Interactive shell企手 覿襴蠍磯 . (defun game-repl () (let ((cmd (game-read))) (unless (eq (car cmd) 'quit) (game-print (game-eval cmd)) (game-repl))))
  • 12. @ Atom 覲 谿, 蟇一 蠏碁Μ螻 NIL
  • 13. 覲 CL-USER> a The variable A is unbound. CL-USER> (defvar a 1) A CL-USER> a 1 CL-USER> (list a) (1) CL-USER> :a :A
  • 14. 一 1234 123.4 覿 123/4 = (/ 123 4) 覲旧 #C(1 2) = (complex 1 2) = 1 + 2i
  • 15. CL-USER> (+ 5/9 3/4) 47/36 CL-USER> (* 2 (+ #c(10 5) 4)) ;; 2 * ( (10 + 5i) + 4) #C(28 10) CL-USER> (expt (expt (expt (expt 10 10) 10) 10) 10) 100000000000000000000000000000000000
  • 16. 谿瑚骸 蟇一 谿 : T 蟇一 : NIL , Common Lisp, NIL螻 () 狩 蟆朱 螳譯狩. 襷豺 C if( x ) x螳 0企 蟇一企手 蟆螻 螳 , 螳螳 蟲(Clojure, Scheme) 谿, 蟇 讌 譟郁唄 るゼ 朱 譯殊.
  • 17. NIL CL-USER> nil NIL CL-USER> () NIL CL-USER> (list) NIL CL-USER> (list nil) (NIL)
  • 18. @ Expression S-expression ? Cons cell? car, cdr ? Cons cell & car, cdr
  • 19. S-expression ? S-expression (Symbolic-expression, sexpr) Atom : | 覲. 蠍一 覲殊 覲企企 一危磯 覓 讌. Expression (x . y) 螳 (form)襯 . (蠍一 x, y s-exression)
  • 20. Cons cell ? constructs memory objects which hold two values or pointers to values. (setf x '(a (r t) b))
  • 21. car, cdr ? car, cdr 企 覿 蟾 "IBM 704" lisp襯 蟲, 轟 "IBM 704" 讌ろ一 企 car, cdr伎. ,企 first rest蟆 朱 caar, cadr, cdadr 譴豌れ 襯 豌危蠍一 覓企Μ螳 . [15 Address][15 Decrement][3 Prefix][3 Tag] car (Contents of the Address part of Register number) cdr (Contents of the Decrement part of Register number) cpr (Contents of the Prefix part of Register number) ctr (Contents of the Tag part of Register number)
  • 22. Cons cell & car, cdr CL-USER> (cons 1 2) (1 . 2) CL-USER> (car '(1 . 2)) 1 CL-USER> (cdr '(1 . 2)) 2 CL-USER> (cons 1 nil) (1) CL-USER> (cons 1 (cons 2 (cons 3 nil))) (1 2 3) CL-USER> (list 1 2 3) (1 2 3)
  • 24. @ Lambda lambda funcall & eval defun (了 -, lambda -) , , 蠏 襯 朱 蠍 豌願企
  • 25. lambda CL-USER> (lambda (x) (+ x 10)) #<FUNCTION (LAMBDA (X)) {2496A42D}> CL-USER> ( (lambda (x y) (+ (* x x) (* y y))) 5 2 ) 29
  • 26. funcall & eval CL-USER> (setq a (lambda (x) (+ x 10))) #<FUNCTION (LAMBDA (X)) {2496A42D}> CL-USER> (funcall a 123) 133 CL-USER> (eval '(funcall a 123)) 133
  • 27. defun CL-USER> (defun sum-of-1-to-n (n) (/ (* n (1+ n)) 2)) SUM-OF-1-TO-N CL-USER> (sum-of-1-to-n 100) 5050
  • 28. ??? (funcall a 10) ?? 蠏碁 (a 10)覃 蟆 螳 Common Lisp Variable螻 Funtion 企螻糾 螳れ. Scheme Variable螻 Function 企螻糾 螳.
  • 30. @ Condition If when Unless Cond
  • 31. if (defun number? (n) (if (zerop n) :zero (if (minusp n) :minus (if (plusp n) :plus :idk))))
  • 32. when, unless (defun number?-when (n) (when (zerop n) (return-from number?-when :zero)) (when (minusp n) (return-from number?-when :minus)) (when (plusp n) (return-from number?-when :plus)) :idk) (defun float?-unless (n) (unless (floatp n) (return-from float?-unless :not-float)) :float)
  • 33. cond (defun number-what3 (n) (cond ((minusp n) :minus) ((zerop n) :zero) ((plusp n) :plus) (t :idk)))
  • 35. Binding let, let* flet, lables Lexical & dynamic
  • 36. Let, let* CL-USER> (let ((x 10) (y 20)) (+ x y)) 30 CL-USER> (let* ((x 10) (y (+ x 20))) y) 30
  • 37. flet, lables CL-USER> (flet ((hello (x) (1- x))) (hello 10)) 9 CL-USER> (labels ((hello (x) (if (> x 3) (hello (1- x)) x))) (hello 10)) 3
  • 38. Lexical & dynamic (defparameter *global* 10) (defun hello () (print *global*)) (let ((x *global*)) (defun hello2 () (print x)))
  • 40. @ LISt Processing Quote, Unquote Macro defmacro
  • 41. Quote, Unquote CL-USER> a 1 CL-USER> (quote a) A CL-USER>a A CL-USER> (list a) (1) CL-USER> (a) (A) CL-USER> `(,a) (1) ` 襯 譯朱, Scheme 企ゼ Quasiquote Common Lisp backquote 覿 襴. CL-USER> `(1 2 ,@(list 3 4)) (1 2 3 4)
  • 42. Macro Lisp form企 object襯 覦 貉危 蟇磯 貊襯 覓碁 豢 蠍磯 螻 Domain-specific language 所 讌. 壱 襷ろ襦 豕 譯手鍵 蟾螻, 螳蟆壱 貊襯 企伎
  • 43. cond macro (defmacro cond (&rest clauses) (when clauses (let* ((this (first clauses)) (others (rest clauses)) (test (first this)) (forms (rest this))) `(if ,test (progn ,@forms) (cond ,@others)))))
  • 44. cond expand (IF (MINUSP N) (PROGN :MINUS) (COND ((ZEROP N) :ZERO) ((PLUSP N) :PLUS) (T :IDK))) (cond ((minusp n) :minus) ((zerop n) :zero) ((plusp n) :plus) (t :idk))
  • 45. DSL
  • 46. @ DSL DSL loop format
  • 47. DSL DSL企? Domain-Specific Language 螳 貊(Intention-revealing code) 轟 覓語襯 蟆朱 貉危 語 External DSLs 讌蠍 螻 語伎 碁 譟伎 DSL. ex) SQL, 蠏 Graphical DSLs 襯 蠍 覓語覲企 伎 DSL ex) UML 覓語 讌襷, れ 覓語襯 願屋蠍 伎 蠏碁れ.. Fluent interfaces Api襯 覦一 所鍵 ク蟆襷. 壱讌 語伎 譯朱 . Internal or embeded DSLs 讌蠍 螻 語企ゼ 蠏碁襦 DSL
  • 48. loop CL-USER> (loop for i from 1 to 10 collect i) (1 2 3 4 5 6 7 8 9 10)
  • 49. format CL-USER> (format nil "~{~a~^, ~} '(1 2 3 4 5)) "1, 2, 3, 4, 5"
  • 50. CLOS
  • 51. clos Common Lisp Object System 螳豌伎レ 讌蠍 , 語願規 蟆 , 襷ろ襦襯 伎 豈.
  • 52. (defclass <POS> () ((x :initarg :x :accessor x) (y :initarg :y :accessor y))) (defun new-pos (x y) (make-instance '<POS> :x x :y y)) (defparameter p1 (new-pos 10 20)) (defmethod print-object ((pos <POS>) stream) (with-slots (x y) pos (format stream "#<Pos ~a, ~a>" x y))) (defmethod rotate ((pos <POS>)) (with-slots (x y) pos (new-pos (- y) x)))
  • 53. (defclass <Rectangle> () ((w :accessor w :initarg :w) (h :accessor h :initarg :h))) (defclass <Circle> () ((r :accessor r :initarg :r))) (defmethod area! ((rectangle <Rectangle>)) (with-slots (w h) rectangle (* w h))) (defmethod area! ((circle <Circle>)) (with-slots (r) circle (* pi (expt r 2)))) (defparameter aa (make-instance '<Rectangle> :w 10 :h 20)) (defparameter bb (make-instance '<Circle> :r 10)) (area! aa) (area! bb)
  • 54. Debug
  • 55. @ Debug step trace declare & disassamble
  • 56. step CL-USER> (step (labels ((hello (x) (if (> x 3) (hello (1- x)) x))) (hello 10)))
  • 57. trace CL-USER> (defun hello (x) (if (> x 3) (hello (1- x)) x)) HELLO CL-USER> (trace hello) (HELLO) CL-USER> (hello 5) 0: (HELLO 5) 1: (HELLO 4) 2: (HELLO 3) 2: HELLO returned 3 1: HELLO returned 3 0: HELLO returned 3 3 CL-USER> (untrace hello) T
  • 58. disassemble (defun add1 (n) (1+ n)) (disassemble 'add1) ; disassembly for ADD1 ; 247C2D38: 840500000021 TEST AL, [#x21000000] ; 3E: 8B55FC MOV EDX, [EBP-4] ; 41: BF04000000 MOV EDI, 4 ; 46: E84DD483FD CALL #x22000198 ; 4B: 7302 JNB L0 ; 4D: 8BE3 MOV ESP, EBX ; 4F: L0: 8BE5 MOV ESP, EBP ; 51: F8 CLC ; 52: 5D POP EBP ; 53: C3 RET ; 54: CC0A BREAK 10 ; 56: 02 BYTE #X02 ; 57: 18 BYTE #X18 ; 58: 4F BYTE #X4F ; ECX
  • 59. declare (defun int-add1 (n) (declare (fixnum n) (optimize (speed 3) (safety 0) (debug 0))) (the fixnum (1+ n))) (disassemble 'int-add1) ; disassembly for INT-ADD1 ; 2489E3E0: 840500000021 TEST AL, [#x21000000] ; no-arg-parsing entry point ; 6: 83C204 ADD EDX, 4 ; 9: 8BE5 MOV ESP, EBP ; B: F8 CLC ; C: 5D POP EBP ; D: C3 RET
  • 61. #include <stdio.h> int hello (int a, int b) { return a + b; } gcc -shared -o test.so test (ql:quickload :cffi) (in-package :cl-user) (defpackage :cffi-exam (:use :cl :cffi)) (in-package :cffi-exam) (define-foreign-library test.so (t (:default "~/tmp/test"))) (use-foreign-library test.so) (defcfun "hello" :int (a :int) (b :int)) (hello 1 2) Cffi-with-gcc
  • 62. Cffi-with-win32 (in-package :cl-user) (defpackage winapi (:use :cl :cffi)) (in-package :winapi) (define-foreign-library user32.dll (t (:default "user32"))) (define-foreign-library kernel32.dll (:windows "kernel32")) (cffi:define-foreign-library gdi32.dll (:windows "gdi32.dll")) (use-foreign-library user32.dll) (use-foreign-library kernel32.dll) (use-foreign-library gdi32.dll) (ql:quickload :cffi)
  • 63. (defctype LPCSTR :string) (defctype HANDLE :pointer) (defctype HWND HANDLE) (DEFCFUN ("MessageBoxA" MessageBox) :INT (HWND HWND) (LPTEXT LPCSTR) (LPCAPTION LPCSTR) (UTYPE :UINT)) (MessageBox (null-pointer) "hello" "world" 0)
  • 65. elisp
  • 66. abcl
  • 69. Common Lisp: A Gentle Introduction to Symbolic Computation
  • 71. The Less than Rapid prototype "Because Lisp and rapid prototyping evolved together, Lisp include a lot of features specifically inteded for prototype: inefficient but convenient features like property lists, keyword parameters, and, for that matter, lists." "It's important to realize, though, that Lisp is a language for writing production software as well as a language for writing prototypes. - 豈 OnLisp - : Paul Graham ( Y Combinator 谿暑曙 )
  • 72. links Peter Seibel's Practical Common Lisp Paul Graham's On Lisp David Lamkin's Successful Lisp Shriram Krishnamurthi's Programming Languages: Application and Interpretation Guy Steele's Common Lisp the Language, 2nd ed. LispWorks HyperSpec.