Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CLOS

Common Lisp Object System

defpackage :hello :use :common-lisp :documentation in-package :hello

(defclass Hello () (name age) ) 에서 C-c C-y하면 (make-instance 'Hello ) 가 입력됨

(setf hello (make-instance 'Hello)) (setf (slot-value hello 'name) "my name") :initform :initarg :reader / :writer / :accesor :documentation :allocation - :class / :instance

(defclass Hello () ((name :documentation "Name" :initarg :name :accessor name))) ;; C-c C-y

(defmethod hi ((o Hello)) (format t "Hello ~a!" (name o)))

(defparameter a (make-instance 'Hello :name "my Name"))

call-next-method // super

(typep a 'BaseA) ;; => T // a is BaseA subtypep ✔️ 타입 vs 타입 비교 // typeof(Derived).IsSubclassOf(typeof(Base)) find-class 클래스 심볼로 클래스 객체를 찾아줌 // typeof class-of 객체가 정확히 어떤 클래스의 인스턴스인지 알려줌 // .GetType()

:before / :after / :around

(defmethod print-object ((o Hello) stream) ) (print-unreadable-object (defmethod INITIALIZE-INSTANCE

다중상속 가능

(defgeneric greet (obj) (:documentation "asdf") (:method ((p person)) ) (:method ((o X)) )) https://github.com/pcostanza/closer-mop

M-x slime-unintern-symbol (fmakunbound 'greet)

MOP

Metaobject Protocol

Closer to MOP

Ref

짚고 넘어가기

  • defclass
  • defmethod