-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
;; 注意,common-lisp 的 class 名字, | ||
;; 直接占用了常用的 object 名, | ||
;; 而不是用 Dog 和 dog 的命名惯例来区分 class 和 object。 | ||
|
||
(defstruct dog name breed age) | ||
(defparameter *rover* | ||
(make-dog :name "rover" | ||
:breed "collie" | ||
:age 5)) | ||
*rover* | ||
(dog-p *rover*) | ||
(dog-name *rover*) | ||
|
||
;; in a new scheme, we can have: | ||
|
||
(define-class dog name breed age) | ||
(define-object *rover* | ||
(new dog | ||
:name "rover" | ||
:breed "collie" | ||
:age 5)) | ||
(define-object *rover* | ||
(new dog | ||
:name "rover" | ||
:breed "collie" | ||
:age 5)) | ||
*rover* | ||
(:p *rover*) | ||
(:name *rover*) | ||
|
||
;; or | ||
|
||
(define-class dog name breed age) | ||
(define-object *rover* | ||
(dog.new | ||
.name "rover" | ||
.breed "collie" | ||
.age 5)) | ||
*rover* | ||
(.p *rover*) | ||
(.name *rover*) |