Created
December 13, 2016 09:39
-
-
Save zhouqiang-cl/4ecae768420937c30d2c06628be79827 to your computer and use it in GitHub Desktop.
common lisp 的对象系统 1 --- slot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
描述 | |
访问器: 通过替一个槽定义一个访问器 (accessor),我们隐式地定义了一个可以引用到槽的函数 | |
缺省值: 指定一个槽的缺省值,可以给入一个 :initform 参数 | |
槽初始化: 想要在 make-instance 调用期间就将槽初始化, 可以用 :initarg 定义一个参数名 | |
代码 | |
* (defclass circle () | |
((radius :accessor circle-radius | |
:initarg :radius | |
:initform 1) | |
(center :accessor circle-center | |
:initarg :center | |
:initform (cons 0 0)))) | |
#<STANDARD-CLASS CIRCLE> | |
* (setf c (make-instance 'circle :radius 3)) | |
#<CIRCLE {1004C4C1F3}> | |
* (circle-radius c) | |
3 | |
* (circle-center c) | |
(0 . 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment