(sb-ext:save-lisp-and-die "hello.exe" :toplevel #'main :executable t)sbcl --load quicklisp.lisp 로 실행하고(quicklisp-quickstart:install) 하면 quicklisp 설치 완료(load "~/quicklisp/setup.lisp")(ql:quickload "usocket")(ql:quickload "bordeaux-threads")(defun test () (print "assdasdasdsadasdasd")) (bordeaux-threads:make-thread #'test)
(defvar clients '())
(defun sendto-all-clients (message) ...)
(defun some-func ()
(let ( (clients *some-sub-list*) )
(sendto-all-clients "hi")
)
)
(NOT (NOT 5))는 5가 아니라 T인가? => T 맞음(RED GREEN BLUE), (AARDVARK), (2 3 5 7 11 13 17)
((BLUE SKY) (GREEN GRASS) (BROWN EARTH))

(A . .png)
<- dotted pair#1=(A B C . #1#) 라고 표기한다(+ 2 3)는 5로 평가된다(+ 1 6) => 7(oddp (+ 1 6)) => t(* 3 (+ 1 6)) => 21(/ (* 2 11) (+ 1 6)) => 22/7(ODDP (+ 1 6))의 evaltrace diagram(평가추적도표?)
(defun average (x y) (/ (+ x y) 2.0))(defun average (x y) (/ (+ x y) 2.0))에서 x와 y가 변수(equal 'kirk 'spock) 따옴표를 붙여(defun test () (* 85 97))


(lambda (x) (+ 3 x))
(if (test) (true-part) (false-part))(defun my-abs (x) (if (< x 0) (- x) x))


(defun nth (n x) "Returns the Nth element of the list X, counting from 0." (car (nthcdr n x)))(defun beforep (x y l) "Returns true if X appears before Y in L" (member y (member x l)))(subsetp '(a i) '(a e i o u)) => t
(funcall #’cons 'a 'b) => (a . b)(mapcar #'(lambda (n) (* n n)) '(1 2 3 4 5))(find-if #'oddp '(2 4 6 7 8 9))
. C) . D) . E)
(defun anyoddp (x)
(cond ((null x) nil)
((oddp (first x)) t)
(t (anyoddp (rest x)))))
(defun factorial (n) (if (zerop n) 1 (* n (factorial (- n 1)))))
(DEFUN func (X)
(COND (end-test-1 end-value-1)
(end-test-2 end-value-2)
(T (func reduced-x))))
(DEFUN func (X)
(COND (end-test end-value)
(T (func reduced-x))))
(DEFUN func (X)
(COND (end-test end-value)
(T (aug-fun aug-val
(func reduced-x)))))

(defun find-number (x)
(cond ((numberp x) x)
((atom x) nil)
(t (or (find-number (car x))
(find-number (cdr x))))))
(LABELS ((fn-1 args-1 body-1)
...
(fn-n args-2 body-2))
body)
~%는 printf의 \n~&는 새로운 줄이 아닐 때만 새로운 줄을 시작~S는 리스프 객체의 문자열 표현 (FORMAT 함수의 나머지 인자들을 채워줘야 한다)~A는 ~S에서 이스케이프 문자를 떼어내고 출력
(defun my-square ()
(format t "Please type in a number: ")
(let ((x (read)))
(format t "The number ~S squared is ~S.~%"
x (* x x))))
(defun riddle ()
(if (yes-or-no-p
"Do you seek Zen enlightenment? ")
(format t "Then do not ask for it!")
(format t "You have found it.")))
*TERMINAL-IO*를 한 번 볼 것. 이게 바로 stream object의 일종(defun my-print (x) (terpri) (prin1 x) (princ " ") x)
(defun read-my-file ()
(with-open-file (stream "/usr/dst/sample-file")
(let ((contents
(read-all-objects stream (list ’$eof$))))
(format t "~&Read ~S objects from the file."
(length contents))
contents)))
(defun read-all-objects (stream eof-indicator)
(let ((result (read stream nil eof-indicator)))
(if (eq result eof-indicator)
nil
(cons result (read-all-objects stream)))))
(setf *total-glasses* 0)*total-glasses*를 갱신
(defun sell (n)
"Ye Olde Lemonade Stand: Sales by the Glass."
(setf *total-glasses* (+ *total-glasses* n))
(format t
"~&That makes ~S glasses so far today."
*total-glasses*))
(SETF A (+ A 5)) => (INCF A 5)(SETF X (CONS 'FOO X)) => (PUSH 'FOO X)
(defun get-name ()
(let ((last-name nil)
(first-name nil)
(middle-name nil)
(title nil))
(format t "~&Last name? ")
(setf last-name (read))
(format t "~&First name? ")
(setf first-name (read))
(format t "~&Middle name or initial? ")
(setf middle-name (read))
(format t "~&Preferred title? ")
(setf title (read))
(list title first-name middle-name last-name)))
> (get-name)
Last name? higginbotham
First name? waldo ; <- 왈도?
Middle name or initial? j
Preferred title? admiral
(ADMIRAL WALDO J HIGGINBOTHAM)
test가 NIL이면 NIL 반환. NIL이 아니면 body를 평가하고 마지막 값을 반환test 판정이 WHEN과 반대(INCF N)은 그 포인터를 4를 가리키는 포인터로 치환한다(setf x ’(jack benny was 39 for many years)) (setf (sixth x) ’several) > x (JACK BENNY WAS 39 FOR SEVERAL YEARS) > (decf (fourth x) 2) 37 > x (JACK BENNY WAS 37 FOR SEVERAL YEARS)
(defun snip (x) (setf (cdr x) (cdr (cdr x)))) > (setf a ’(no down payment)) (NO DOWN PAYMENT) > (setf b (cdr a)) (DOWN PAYMENT) > (snip a) (PAYMENT) > a (NO PAYMENT) > b (DOWN PAYMENT)

> (setf x nil) NIL > (setf y '(no luck today)) (NO LUCK TODAY) > (nconc x y) (NO LUCK TODAY) > x ; 주의!!! NIL > (setf x (nconc x y)) ; 이렇게 써야 안전 ㅋ (NO LUCK TODAY)
(DOTIMES (index-var n [result-form]) body)(DOLIST (index-var list [result-form]) body)(dolist (x '(red blue green) 'flowers) (format t "~&Roses are ~S." x))
(defun find-first-odd (list-of-numbers)
(dolist (e list-of-numbers)
(format t "~&Testing ~S..." e)
(when (oddp e)
(format t "found an odd number.")
(return e))))
(DO ((var1 init1 [update1])
(var2 init2 [update2])
...)
(test action-1 ... action-n)
body)
(defun launch (n)
(do ((cnt n (- cnt 1)))
((zerop cnt) (format t "Blast off!"))
(format t "~S..." cnt)))
RETURN x는 RETURN-FROM NIL x이다
(defun find-first-odd (x)
(format t "~&Searching for an odd number...")
(dolist (element x)
(when (oddp element)
(format t "~&Found ~S." element)
(return-from find-first-odd element)))
(format t "~&None found.")
'none)
(defun foo (x &optional y) (format t "~&X is ~S" x) (format t "~&Y is ~S" y) (list x y)) > (foo 3 5) X is 3 Y is 5 (3 5) > (foo 4) X is 4 Y is NIL ; 기본값은 NIL (4 NIL)
(defun divide-check (dividend &optional (divisor 2)) ; divisor라고 쓰는 대신 (divisor 2)로 묶어줌
(format t "~&~S ~A divide evenly by ~S"
dividend
(if (zerop (rem dividend divisor)) "does" "does not")
divisor))
(defun average (&rest args)
(/ (reduce #’+ args)
(length args)
1.0))
&key를 사용한다
(defun make-sundae (name &key (size 'regular)
(ice-cream 'vanilla)
(syrup 'hot-fudge)
nuts
cherries
whipped-cream)
(...body...))
&aux
(defun average (&rest args
&aux (len (length args)))
(/ (reduce #’+ args) len 1.0))
(typep 3 'number) => t(typep 3 'integer) => t(typep 3 'float) => nil(typep 'foo 'symbol) => t
(defstruct starship (name nil) (speed 0) (condition 'green) (shields 'down))
> (setf s1 (make-starship)) #S(STARSHIP NAME NIL SPEED 0 CONDITION GREEN SHIELDS DOWN)
> (setf s2 '#s(starship speed (warp 3)
condition red
shields up))
(defun print-starship (x stream depth)
(format stream "#<STARSHIP ~A>"
(starship-name x)))
(defstruct (starship
(:print-function print-starship)) ; 여기가 중요!!
(captain nil)
(name nil)
(shields ’down)
(condition ’green)
(speed 0))
(defstruct ship (name nil) (captain nil) (crew-size nil)) (defstruct (starship (:include ship)) (weapons nil) (shields nil))

> (setf *print-array* nil)
NIL
> my-vec
#<Vector {204844}>
> (setf *print-array* t)
T
> my-vec
#(TUNING VIOLIN 440 A)
#\k => #\k> (setf h (make-hash-table)) #<EQL Hash table 5173142> > (type-of h) HASH-TABLE
(ind-1 value-1 ind-2 value-2 ...)
(defmacro while (test &body body)
'(do ()
((not ,test))
,@body))
(defmacro mix-and-match (p q)
(let ((x1 (first p)) (y1 (second p)) (x2 (first q)) (y2 (second q)))
`(list '(,x1 ,y1) '(,x1 ,y2) '(,x2 ,y1) '(,x2 ,y2))))
;; 위에 걸 이렇게 쓸 수 있다
(defmacro mix-and-match ((x1 y1) (x2 y2))
`(list '(,x1 ,y1) '(,x1 ,y2) '(,x2 ,y1) '(,x2 ,y2)))
| 표현식 | 값 | |
| (class-of 'a) | #<Built-In-Class SYMBOL> | |
| (class-of "a") | #<Built-In-Class STRING> | |
| (class-of 12) | #<Built-In-Class INTEGER> | |
| (class-of '(a b)) | #<Built-In-Class CONS> | |
| (class-of '#(a b c)) | #<Built-In-Class VECTOR> | |
(DEFCLASS class-name (superclass-name*) (slot-description*) class-option*)
(MAKE-INSTANCE class {initarg value}*)(DEFMETHOD generic-function-name specialized-lambda-list form*)