728x90
1. Types
- type & type-of : 어떤 데이터 타입인지
- (typep '변수 '데이터타입) = t/nil
- (type-of '변수) = 데이터 타입리턴
- (typep #'list 'funtion) 함수는 #' 붙여줘야함
2. Structures
- Structures: 내가 정의한 데이터타입
- DEFSTRUCT: 새로운 데이터 타입 정의
(defstruct starship
(captain nil)
(name nil)
(speed 0)
(condition ‘green)
(shields ‘down))
(setf s1 (make-starship)) //구조체 선언
(starship-captain) //구조체안 변수 접근
- 응용
(defun alert (x) ;; causing a starship to raise its shields
(setf (starship-shields x) 'up)
(if (equal (starship-condition x) 'green)
(setf (starship-condition x) 'yellow))
'shields-raised)
//초기화 하기
(setf s3 (make-starship :name "Reliant"
:shields ‘damaged))
- 구조체 equality
(setf s5 (make-starship))
(setf s6 (make-starship))
(equal s5 s6) >> nil
(equalp s5 s6) >> t
3. Inheritance(상속)
- :INCLUDE option : 구조체 상속하는 옵션이다
(defstruct ship
(name nil)
(captain nil)
(crew-size nil))
(defstruct (starship (:include ship))
(weapons nil)
(shields nil))
(defstruct (supplyship (:include ship))
(cargo nil))
4. Describe
- 구조체 내용을 출력해준다.
728x90
'Major > Lisp' 카테고리의 다른 글
[Lisp] Tic-Tac-Toe 게임 실습(2) (0) | 2021.06.09 |
---|---|
[Lisp] Chapter 13 Arrays(배열)* (0) | 2021.06.09 |
[Lisp] Tic-Tac-Toe 게임 실습(1) (0) | 2021.06.09 |
[Lisp] Chapter 10 Assignment (0) | 2021.06.09 |
[Lisp] Ch 9 - Input/Output (0) | 2021.06.01 |