構造体
Lispの構造体はLispチックで非常にかっこいい。
ちなみにどんなコードが展開されているのか気になって見てみた。(CLISP)
凄い量ですね・・・。
xyzzyとは出力が結構違う。
CLISPにはCLOSという文字が出てきている。
構造体も実はクラスとか・・・?
CLOSはまだ全然勉強していないのでソースがいまいち分かりません。
# 大文字のままだと非常に見づらいので結果は小文字に変換してます
>(string-downcase (write-to-string (macroexpand '(defstruct foo value1)))) (eval-when (load compile eval) (let nil (let ((#:g3097 (cons 'foo (clos::class-names (get 'structure-object 'clos::closclass))))) (system::structure-undefine-accessories 'foo) (remprop 'foo 'system::defstruct-description) (clos::define-structure-class 'foo #:g3097 'make-foo 'nil 'copy-foo 'foo-p (list (clos::make-instance-<structure-effective-slot-definition> clos::<structure-effective-slot-definition> :name 'value1 :initargs '(:value1) :type 't :allocation ':instance 'clos::inheritable-initer (clos::make-inheritable-slot-definition-initer 'nil (system::make-constant-initfunction nil)) 'clos::inheritable-doc '(nil) 'clos::location '1 'clos::readonly 'nil)) (list (clos::make-instance-<structure-direct-slot-definition> clos::<structure-direct-slot-definition> :name 'value1 :initargs '(:value1) :type 't :allocation ':instance 'clos::inheritable-initer (clos::make-inheritable-slot-definition-initer 'nil (system::make-constant-initfunction nil)) 'clos::inheritable-doc '(nil) :readers '(foo-value1) :writers '((setf foo-value1))))) (defun make-foo (&key (#:value1 nil)) (let ((system::object (system::%make-structure #:g3097 2))) (setf (system::%structure-ref 'foo system::object 1) (the t #:value1)) system::object))) (proclaim '(inline foo-p)) (defun foo-p (system::object) (system::%structure-type-p 'foo system::object)) (proclaim '(inline copy-foo)) (defun copy-foo (structure) (copy-structure structure)) (proclaim '(function foo-value1 (foo) t)) (proclaim '(inline foo-value1)) (defun foo-value1 (system::object) (the t (system::%structure-ref 'foo system::object 1))) (system::%put 'foo-value1 'system::defstruct-reader 'foo) (proclaim '(function (setf foo-value1) (t foo) t)) (proclaim '(inline (setf foo-value1))) (defun (setf foo-value1) (system::value system::object) (system::%structure-store 'foo system::object 1 system::value)) (system::%put 'foo-value1 'system::defstruct-writer 'foo) (system::%set-documentation 'foo 'type nil) (clos::defstruct-remove-print-object-method 'foo) 'foo))