CL-USER> (format t "~a (~r)~%" most-negative-fixnum most-negative-fixnum) -536870912 (minus five hundred and thirty-six million eight hundred and seventy thousand nine hundred and twelve) NIL
CL-USER> (format t "~a~%~r~%" most-positive-fixnum most-positive-fixnum) 536870911 five hundred and thirty-six million eight hundred and seventy thousand nine hundred and eleven NIL
----------------------------------------------------------------- CL-USER> (format t "~a~%" most-negative-short-float) -3.4028172S38 NIL
CL-USER> (format t "~a~%" most-positive-short-float) 3.4028172S38 NIL
----------------------------------------------------------------- CL-USER> (format t "~a~%" most-negative-single-float) -3.4028235E38 NIL
CL-USER> (format t "~a~%" most-positive-single-float) 3.4028235E38 NIL
----------------------------------------------------------------- CL-USER> (format t "~a~%" most-negative-double-float) -1.7976931348623158D308 NIL
CL-USER> (format t "~a~%" most-positive-double-float) 1.7976931348623158D308 NIL
----------------------------------------------------------------- CL-USER> (format t "~a~%" most-negative-long-float) -1.7976931348623158D308 NIL
CL-USER> (format t "~a~%" most-positive-long-float) 1.7976931348623158D308 NIL
CL-USER 2 > (if (symbolp day-or-date) 'day 'date)
DAY
CL-USER 3 > (setf day-or-date 9)
9
CL-USER 4 > (if (symbolp day-or-date) 'day 'date)
DATE
CL-USER 5 > (if (numberp day-or-date) 'day 'date)
DAY
;;; (when (조건) 참-실행문들)
;;; (when <test> <then forms>) ;;; (if <test> <then form> nil) ;- i f 의 불필요한 <else form> 부분 평가가 필요없을 때,
;- 단순히 참인 경우만 확인하여 실행하고자 할 때
CL-USER 14 : 1 > (setf high 98 temperature 102)
102
CL-USER 15 : 1 > (when (> temperature high) (setf high temperature) 'new-record)
NEW-RECORD
CL-USER 16 : 1 > high
102
;;; (unless (조건) 거짓-실행문들) ;;; (unless <test> <else forms>) ;;; (if <test> nil <else form>) ;- i f 의 불필요한 <then form> 부분 평가가 필요없을 때,
;- 단순히 거짓인 경우만 확인하여 실행하고자 할 때
;;; (cond (조건 절1) (조건 절2) (조건 절3) ... (t 절)) ;;; if, when, then 보다 훨씬 유연한 조건 실행을 위한 cond
;;; 즉, cond으로 위 모든 논리회로를 구성할 수 있다.
;;; 각 조건절 하나씩이 when 절과 같은 역할 수행 중
;;;; (cond (<test 1> <cosequnce 1-1> ...)
;;;; (<test 2> <cosequnce 2-1> ...)
;;;; ....
;;;; (<test n> <cosequnce n-1> ...))
;- (when 1), (when 2), (when 3), ... (when n)의 경우를 한꺼번에 설정한 효과
;- <test> 중 nonNil인 것을 찾아서 실행하는 기능, 이를 triggered clause라 함.
;- 반환값은 triggered clause 중에서 마지막 consequnce form이 된다.
;- 모든 <test>가 Nil이면 전체 반환값은 Nil
CL-USER 17 : 1 > (setf thing 'sphere r 1)
1
CL-USER 18 : 1 > (cond ((eq thing 'circle) (* pi r r))
((eq thing 'sphere) (* 4 pi r r)))
12.566370614359173D0
CL-USER 19 : 1 > (cond ((eq thing 'circle) (* pi r r))
(t (* 4 pi r r))) ;;- 마지막 조건을 t로 하는 경우
12.566370614359173D0
CL-USER 20 : 1 > (cond ((eq thing 'circle) (* pi r r))
((* 4 pi r r))) ;;- 마지막 조건을 안다는 경우
;;- 이는 test form이자 value form
12.566370614359173D0
CL-USER 22 : 1 > (setf p .6)
0.6
CL-USER 23 : 1 > (cond ((> p .76) 'very-likely)
((> p .5) 'likely)
((> p .25) 'unlikely)
(t 'very-unlikely))
LIKELY
CL-USER 24 : 1 > (defun rightp (a b c) ;; 변의 길이를 톻애 직각 삼각형 여부 판단
(cond ((eq (max a b c) a) (eq (expt a 2) (+ (expt b 2) (expt c 2))))
((eq (max a b c) b) (eq (expt b 2) (+ (expt a 2) (expt c 2))))
(t (eq (expt c 2) (+ (expt b 2) (expt a 2))))))
RIGHTP
;;; (case <key form> (key1 실행문들> ... <otherwise 실행문>)
;;;; (case <key form>
;;;; (<key 1> <cosequnce 1-1> ...)
;;;; (<key 2> <cosequnce 2-1> ...)
;;;; ....
;;;; (<key n> <cosequnce n-1> ...))
;- key form과 key들을 eq가 아닌 eql로 비교하여 매치되면 해당 절을 실행
;- Nil 반환값을 막기 위해 마지막 절을 t 또는 otherwise로 시작
CL-USER 40 : 7 > (setf thing 'point r 1)
1
CL-USER 41 : 7 > (case thing
(circle (* pi r r))
(sphere (* 4 pi r r))
(t 0))
0
CL-USER 42 : 7 > (setf thing 'ball r 1)
1
CL-USER 43 : 7 > (case thing
((circle wheal) (* pi r r))
((sphere ball) (* 4 pi r r))
(otherwise 0))
12.566370614359173D0
;;; (and (조건1) (조건2) (조건3) ... (조건n))
;- 조건 중 어느 것 하나라도 처음에 거짓이면 더 이상 진행 않는다. >> Nil
;- 모든 조건이 참이이면 제일 마지막 반환값을 반환한다.
;- Nil이 아닌 반환값을 반환할 때는 모든 조건이 참이었음을 알 수 있다.
;;; (or (조건1) (조건2) (조건3) ... (조건n))
;- 조건 중 처음 어느 것 하나라도 참이면 더 이상 진행 않는다. >> 그 참인 것의 반환값
;- 모든 조건이 거젓이이면 >> Nil
;- Nil이 아닌 반환값을 반환할 때는 적어도 하나가 참이었음을 알 수 있다.
;;; (not (조건))
;- 존재의 유무 확인 또는 명제의 역
;- 단순히 notNil한 변수에 대하여 Nil을, Nil을 T로 전한하는 역할 수행
;- 논리적인 관계를 다루며, 리스트에서 이에 상응하는 것은 null 이다.
;- 반환값은 2가지 뿐 T / Nil
;;;; Predicates ;;;;;;
;- 참 또는 거짓만을 반환하는 procedure
;- 반한값이 t 또는 nil
null ;;; 원래 빈 리스트인가? data type test
endp ;;; 리스트가 다 비었는가? btter
> ;;; 점점 작아지는가? 내림차순으로 배열되어 있는가?
< ;;; 점점 커지는가? 오름차순으로 배열되어 있는가?
= ;;; same number? / effcient
eq ;;; same symboll? / efficient
eql ;;; same typed number or symbol? /efficient
equal ;;; same expression? / for ATOM or LIST / expensive