From b9a5328d0e65bc8bbf72332aef34119162f34d3c Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Mon, 12 Aug 2024 09:05:20 +0800 Subject: [PATCH] up --- docs/archive/oop-by-sexp/common-like-oop.lisp | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 docs/archive/oop-by-sexp/common-like-oop.lisp diff --git a/docs/archive/oop-by-sexp/common-like-oop.lisp b/docs/archive/oop-by-sexp/common-like-oop.lisp new file mode 100644 index 0000000..a42d7ae --- /dev/null +++ b/docs/archive/oop-by-sexp/common-like-oop.lisp @@ -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*)