Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Aug 12, 2024
1 parent 1381b37 commit b9a5328
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/archive/oop-by-sexp/common-like-oop.lisp
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*)

0 comments on commit b9a5328

Please sign in to comment.