[Lisp] Chapter 12 구조체(Structures)

2021. 6. 9. 04:12·Major/Lisp
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
'Major/Lisp' 카테고리의 다른 글
  • [Lisp] Tic-Tac-Toe 게임 실습(2)
  • [Lisp] Chapter 13 Arrays(배열)*
  • [Lisp] Tic-Tac-Toe 게임 실습(1)
  • [Lisp] Chapter 10 Assignment
BeNI
BeNI
코딩하는 블로그
  • BeNI
    코딩못하는컴공
    BeNI
  • 전체
    오늘
    어제
    • Menu (253)
      • My profile (1)
      • 회고 | 후기 (8)
      • Frontend (65)
        • Article (11)
        • Study (35)
        • 프로그래머스 FE 데브코스 (19)
      • Backend (0)
      • Algorithm (58)
        • Solution (46)
        • Study (12)
      • Major (111)
        • C&C++ (23)
        • Java (20)
        • Data Structure (14)
        • Computer Network (12)
        • Database (15)
        • Linux (6)
        • Architecture (3)
        • Lisp (15)
        • OS (1)
        • Security (2)
      • etc (2)
  • 링크

    • 깃허브
    • 방명록
  • 인기 글

  • 최근 댓글

  • 최근 글

  • 태그

    자료구조
    백준
    파일처리
    프로그래머스
    C++
    리팩토링
    데브코스
    Algorithm
    react
    lisp
  • hELLO· Designed By정상우.v4.10.2
BeNI
[Lisp] Chapter 12 구조체(Structures)
상단으로

티스토리툴바