This is the structure-ext Reference Manual, version 0.0.3, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 07:48:01 2024 GMT+0.
structure-ext/structure-ext.asd
structure-ext.left-arrow-accessors/structure-ext.left-arrow-accessors.asd
structure-ext.make-instance/structure-ext.make-instance.asd
structure-ext.as-class/structure-ext.as-class.asd
structure-ext/package.lisp
structure-ext.left-arrow-accessors/left-arrow-accessors.lisp
structure-ext.make-instance/make-instance.lisp
structure-ext.as-class/as-class.lisp
The main system appears first, followed by any subsystem dependency.
structure-ext
Tiny structure extensions
Shinichi Sato
MIT
0.0.3
structure-ext.left-arrow-accessors
(system).
structure-ext.make-instance
(system).
structure-ext.as-class
(system).
package.lisp
(file).
structure-ext.left-arrow-accessors
Slot accessor alias maker.
Shinichi Sato
MIT
# STRUCTURE-EXT.LEFT-ARROW-ACCESSORS 0.0.6
## introduction
Any language has direction.
In this context, "direction" means order of explain.
For example, English has "from center to around" direction, and Japanese has "from around to center" direction.
E.g. person name.
In English notation, my name is written as ’Shinichi Sato’.
Shinichi is first name (of course center), and Sato is family name (of course around).
But in Japanese notation, my name is written as "佐藤 真一".
"佐藤" equals "Sato", and "真一" equals "Shinichi".
Also day unit.
In English notation, its written "Day Month Year".
It aims from small unit to bigger unit.
But in Japanese notation, its written "年月日".
"年" equals "year", "月" equals "month", and "日" equals "Day".
It aims from big unit to smaller unit.
Also address notations.
In English notation, its written from small place like town to huge place like prefecture, state, etc...
But in Japanese notation, its written from huge place like prefecture to small place like town, street etc...
Of course each language has inversion though.
Also programming language is one kind of language.
In such context, we can refer center as "return value", and around as "algorithm".
Roughly, we can say imperative language has Japanese style "from around to center" direction, and functional language has English style "from center to around" direction.
## Current lisp world
In lisp comunity, functional programming style is recommended.
Language is carefully designed to be able to write functional style easily.
For example, LET’s binding is designed "from center to around"(var is center(It is what we want.), and init form is around.), METHOD’s specializer is designed so too, WITH-SLOTS’s alias is same, etc...
## Issues
But there is few "from around to center" rule in CL.
It is slot accessor or slot accessor style function name like CHAR-CODE.
## Proposal
Using left arrow instead of hyphen is proposed.
Do you think which code is easy to understand?
“‘lisp
(code-char n)
(char<=code n)
“‘
I bet it is almost same.
There is just small differences only.
But in many cases, we don’t write such low level code as toplevel.
Usually we nests it.
So how below?
“‘lisp
(defun example1 (symbol)
(let ((name (package-name (symbol-pakcage symbol))))
...))
(defun example2 (symbol)
(let ((name (name<=package (package<=symbol symbol))))
...))
“‘
In former case, relational part appears alternately.
While reading code from left to right, the stack in your brain acting violently like seesaw but later case.
There is no probrem with class, because we can specify arbitraly name as readers/writers/accessors, but structure.
## Usage
“‘lisp
(defstruct foo bar)
(DEFINE-LEFT-ARROW-ACCESSORS foo bar)
(bar<=foo (make-foo :bar 0))
=> 0
“‘
## From developer
* Product’s goal - already?
* License - MIT
### Tested
* SBCL/2.0.2
* CCL/1.12
* CLISP/2.49
* ECL/20.4.24
0.0.7
left-arrow-accessors.lisp
(file).
structure-ext.make-instance
Method make-instance for construct structure.
Shinichi Sato
MIT
0.1.1
closer-mop
(system).
make-instance.lisp
(file).
structure-ext.as-class
Defstruct as defclass
Shinichi Sato
MIT
# STRUCTURE-EXT.AS-CLASS 0.0.6
## Current lisp world
Common Lisp has strong structure and class.
## Issues
In Common Lisp comunity, subject ’structure vs class’ is issued sometimes.
Only structure can do is nothing.
Only class can do is Multiple inheritance.
NOTE - Here, we ignores the thing which can not do but there is a way.
E.g. class is unreadable, but we can write reader macro.
E.g. structure does not have shared slot, but we can emulate it with symbol-plist.
So roughly, we can say ’if you need multiple inheritance, use class. otherwise structure. Because structure is fast.’
“‘Lisp
(defstruct foo slot)
(defclass bar () ((slot :initarg :slot :accessor bar-slot)))
;; constructor
(time (dotimes (x 1000) (make-foo :slot 0)))
=> 299,098 processor cycles
16,376 bytes consed
(time (dotimes (x 1000) (make-instance ’bar :slot 0)))
=> 19,777,048 processor cycles
187,400 bytes consed
;; 66 times faster, 11.5 times less consed.
;; accessor
(let ((s (make-foo :slot 0)))
(time (dotimes (x 1000) (foo-slot s))))
=> 26,771 processor cycles
(let ((c (make-instance ’bar :slot 0)))
(time (dotimes (x 1000) (bar-slot c))))
=> 143,488 processor cycles
;; 5.3 times faster.
“‘
## Proposal
DEFSTRUCT\* is almost same syntax with CL:DEFSTRUCT, but expanded into DEFCLASS and DEFMETHOD forms.
At first, start to write your application with CL:DEFSTRUCT.
If you need multiple inheritance, change CL:DEFSTRUCT to DEFSTRUCT\*, and add super class as :include option.
DEFSTRUCT\* can accept multiple :include options.
## Constraints
### Invalid options
Option :type, :named, and :initial-offset are invalid in DEFSTRUCT\*
### Uncompleteness of copier
The copy function which is made by DEFSTRUCT\* has some constraints.
* Any slots has CL:ERROR initform.
* All slots are not specified :READ-ONLY T.
Because, copier evaluates ‘CL:MAKE-INSTANCE‘ without any initargs,
then ‘CL:SETF‘ each slots.
## Usage
## From developer
* Product’s goal - already?
* License - MIT
### Tested
* SBCL/2.0.2
* CCL/1.12
* CLISP/2.49
* ECL/20.4.24
0.0.8
lambda-fiddle
(system).
closer-mop
(system).
uiop
(system).
as-class.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
structure-ext/structure-ext.asd
structure-ext.left-arrow-accessors/structure-ext.left-arrow-accessors.asd
structure-ext.make-instance/structure-ext.make-instance.asd
structure-ext.as-class/structure-ext.as-class.asd
structure-ext/package.lisp
structure-ext.left-arrow-accessors/left-arrow-accessors.lisp
structure-ext.make-instance/make-instance.lisp
structure-ext.as-class/as-class.lisp
structure-ext.left-arrow-accessors/structure-ext.left-arrow-accessors.asd
structure-ext.left-arrow-accessors
(system).
structure-ext.make-instance/structure-ext.make-instance.asd
structure-ext.make-instance
(system).
structure-ext.as-class/structure-ext.as-class.asd
structure-ext.as-class
(system).
structure-ext.left-arrow-accessors/left-arrow-accessors.lisp
structure-ext.left-arrow-accessors
(system).
define-left-arrow-accessors
(macro).
missing-symbol
(condition).
accessors
(function).
left-arrow-names
(function).
the-defun-forms
(function).
the-setf-forms
(function).
structure-ext.make-instance/make-instance.lisp
structure-ext.make-instance
(system).
structure-ext.as-class/as-class.lisp
structure-ext.as-class
(system).
defstruct*
(macro).
accessors
(function).
check
(function).
collect-option
(function).
conc-name
(function).
constructors
(function).
copier
(function).
enslot
(function).
may-documentation
(function).
may-generic
(function).
may-initargs
(function).
method-name
(function).
parse
(function).
predicate
(function).
print-function
(function).
slots
(function).
slots<=obj
(function).
super-classes
(function).
Packages are listed by definition order.
structure-ext.left-arrow-accessors
larac
common-lisp
.
define-left-arrow-accessors
(macro).
missing-symbol
(condition).
accessors
(function).
left-arrow-names
(function).
the-defun-forms
(function).
the-setf-forms
(function).
structure-ext
common-lisp
.
structure-ext.as-class
.
structure-ext.left-arrow-accessors
.
structure-ext.as-class
as-class
common-lisp
.
defstruct*
(macro).
accessors
(function).
check
(function).
collect-option
(function).
conc-name
(function).
constructors
(function).
copier
(function).
enslot
(function).
may-documentation
(function).
may-generic
(function).
may-initargs
(function).
method-name
(function).
parse
(function).
predicate
(function).
print-function
(function).
slots
(function).
slots<=obj
(function).
super-classes
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
# DEFINE-LEFT-ARROW-ACCESSORS
## Description:
Define accessor aliases.
“‘lisp
#?(defstruct foo bar bazz)
=> FOO
, :lazy
“‘
“‘lisp
#?(define-left-arrow-accessors foo bar)
=> (BAR<=FOO)
, :test
“‘
“‘lisp
#?(bar<=foo (make-foo :bar 0))
=> 0
, :around
“‘
“‘lisp
#?(bazz<=foo (make-foo :bazz 0))
:signals (or undefined-function
warning ; for ccl
)
“‘
### syntax
(DEFINE-LEFT-ARROW-ACCESSORS type &rest slot\*)
=> result
## Arguments and Values:
type := symbol which is structure name, otherwise error.
“‘lisp
#?(define-left-arrow-accessors "FOO" bazz)
:signals error
“‘
“‘lisp
#?(define-left-arrow-accessors bar bazz)
:signals error
“‘
slot* := symbol which is slot-name, otherwise error.
“‘lisp
#?(define-left-arrow-accessors foo "BAR")
:signals error
“‘
“‘lisp
#?(define-left-arrow-accessors foo hoge)
:signals error
“‘
result := list which includes defined accessor names.
## Affected By:
lisp image status.
## Side-Effects:
define new functions in current package.
## Notes:
## Exceptional-Situations:
# DEFSTRUCT\*
## Description:
Define class by defstruct syntax.
### syntax
(DEFSTRUCT\* &body body)
=> result
“‘lisp
#?(defstruct* foo bar)
=> FOO
, :lazy
“‘
“‘lisp
#?(make-foo)
:be-the foo
“‘
“‘lisp
#?(foo-bar (make-foo :bar 0))
=> 0
“‘
“‘lisp
#?(foo-p (make-foo))
:satisfies identity
“‘
“‘lisp
#?(let* ((foo (make-foo :bar 0))
(copied (copy-foo foo)))
(values (eq foo copied)
(foo-bar copied)))
:multiple-value-satisfies (lambda ($samep $copied-bar-value)
(& (null $samep)
(= 0 $copied-bar-value)))
“‘
## Arguments and Values:
see CL:DEFSTRUCT.
## Affected By:
none
## Side-Effects:
none
## Notes:
## Exceptional-Situations:
:initial-offset, :type and :named option is invalid.
“‘lisp
#?(defstruct* (bar (:type list))
hoge fuga)
:signals error
“‘
“‘lisp
#?(defstruct* (bar (:initial-offset 4))
hoge fuga)
:signals error
“‘
specify both :print-function and :print-object is invalid.
“‘lisp
#?(defstruct* (bar (:print-function bar-printer)
(:print-object (lambda (&rest args) (print args))))
hoge fuga)
:signals error
“‘
## Examples
simplest form
“‘lisp
#?(defstruct* hoge bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor hoge-bar)))
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
with initform.
“‘lisp
#?(defstruct* hoge
(bar 0))
; <— specified.
:expanded-to
“‘
Specify type.
“‘lisp
#?(defstruct* hoge
(bar 0 :type integer))
; <— specified.
:expanded-to
“‘
Specify read-only T.
“‘lisp
#?(defstruct* hoge
(bar 0 :read-only T))
; <— specified.
:expanded-to
“‘
Conc-name option example.
Specify no prefix.
“‘lisp
#?(defstruct* (hoge (:conc-name nil)) ; <— Specify.
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor bar))) ; <— This!
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
Same above.
“‘lisp
#?(defstruct* (hoge (:conc-name)) bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor bar))) ; <— This!
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
Specify alternative.
“‘lisp
#?(defstruct* (hoge (:conc-name hoge-)) ; <— Specify
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor hoge-bar))) ; <— This!
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
Can use string-designator.
“‘lisp
#?(defstruct* (hoge (:conc-name "hoge-")) ; <— use string.
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor |hoge-BAR|))) ; <— This!
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
Examples of :constructor option.
“‘lisp
#?(defstruct* (hoge (:constructor make)) ; <— Specify.
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor hoge-bar)))
(defun make ; <— This!
(&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
“‘lisp
#?(defstruct* (hoge (:constructor)) ; <— No arg means use default.
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor hoge-bar)))
(defun make-hoge ; <— This!
(&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
“‘lisp
#?(defstruct* (hoge (:constructor create-hoge
(a &optional b (c ’sea) &rest d &aux e (f ’eff))))
a b c d e f)
:expanded-to (progn (defclass hoge ()
((a :initform nil :initarg :a :accessor hoge-a)
(b :initform nil :initarg :b :accessor hoge-b)
(c :initform nil :initarg :c :accessor hoge-c)
(d :initform nil :initarg :d :accessor hoge-d)
(e :initform nil :initarg :e :accessor hoge-e)
(f :initform nil :initarg :f :accessor hoge-f)))
;; This!
(defun create-hoge (a &optional b (c ’sea) &rest d &aux e (f ’eff))
(make-instance ’hoge :a a :b b :c c :d d :e e :f f))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
Examples of :copier option.
“‘lisp
#?(defstruct* (hoge (:copier nil)) ; specify nil.
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor hoge-bar)))
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
;; No cpier!
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
“‘lisp
#?(defstruct* (hoge (:copier hoge)) ; specify name.
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor hoge-bar)))
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
;; This!
(defgeneric hoge (arg))
;; Also!
(defmethod hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
Examples of :include option.
“‘lisp
#?(defstruct* (hoge (:include foo)) fuga)
:expanded-to (progn (defclass hoge (foo) ; <— This!
((fuga :initform nil :initarg :fuga :accessor hoge-fuga)))
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
;; These!
(defgeneric hoge-bar (arg))
(defmethod hoge-bar ((arg hoge))
(foo-bar arg))
(defgeneric (setf hoge-bar) (new arg))
(defmethod (setf hoge-bar) (new (arg hoge))
(setf (foo-bar arg) new))
’hoge)
“‘
Some :include options are valid.
Lets say another object bazz.
“‘lisp
#?(defstruct* bazz
(piyo 0 :read-only t))
=> BAZZ
, :lazy
“‘
“‘lisp
#?(defstruct* (hoge (:include foo)
(:include bazz)) ; <— This!
fuga)
:expanded-to (progn (defclass hoge (foo bazz) ; <— This!
((fuga :initform nil :initarg :fuga :accessor hoge-fuga)))
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
;; These!
(defgeneric hoge-bar (arg))
(defmethod hoge-bar ((arg hoge))
(foo-bar arg))
(defgeneric (setf hoge-bar) (new arg))
(defmethod (setf hoge-bar) (new (arg hoge))
(setf (foo-bar arg) new))
(defgeneric hoge-piyo (arg))
(defmethod hoge-piyo ((arg hoge))
(bazz-piyo arg))
’hoge)
“‘
Slot description example.
“‘lisp
#?(defstruct* (hoge (:include foo (bar 0)))
fuga)
:expanded-to (progn (defclass hoge (foo)
((fuga :initform nil :initarg :fuga :accessor hoge-fuga))
(:default-initargs :bar 0)) ; <— This!
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
(defgeneric hoge-bar (arg))
(defmethod hoge-bar ((arg hoge))
(foo-bar arg))
(defgeneric (setf hoge-bar) (new arg))
(defmethod (setf hoge-bar) (new (arg hoge))
(setf (foo-bar arg) new))
’hoge)
“‘
Examples of :predicate option.
“‘lisp
#?(defstruct* (hoge (:predicate nil)) ; specify nil.
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor hoge-bar)))
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
;; No predicate!
’hoge)
“‘
“‘lisp
#?(defstruct* (hoge (:predicate hoge)) ; specify name.
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor hoge-bar)))
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
;; This!
#+(or clisp sbcl)
(defun hoge (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge (arg))
#-(or clisp sbcl)
(defmethod hoge ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
:print-function
“‘lisp
#?(defstruct* (hoge (:print-function printer)) ; <— specify
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor hoge-bar)))
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
;; This!
(defmethod print-object ((obj hoge) stream)
(printer obj stream *print-level*))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
:print-object
“‘lisp
#?(defstruct* (hoge (:print-object printer)) ; <— specify
bar)
:expanded-to (progn (defclass hoge ()
((bar :initform nil :initarg :bar :accessor hoge-bar)))
(defun make-hoge (&rest args)
(apply #’make-instance ’hoge args))
;; This!
(defmethod print-object ((obj hoge) stream)
(printer obj stream))
(defgeneric copy-hoge (arg))
(defmethod copy-hoge ((arg hoge))
(let ((obj (make-instance (class-of arg))))
(dolist (slot (slots<=obj arg))
(if (slot-boundp arg slot)
(setf (slot-value obj slot) (slot-value arg slot))
(slot-makunbound obj slot)))
obj))
#+(or clisp sbcl)
(defun hoge-p (arg) (typep arg ’hoge))
#-(or clisp sbcl)
(defgeneric hoge-p (arg))
#-(or clisp sbcl)
(defmethod hoge-p ((arg hoge)) arg)
#-(or clisp sbcl)
(defmethod hoge-p (arg)
(declare (ignore arg))
nil)
’hoge)
“‘
# MISSING-SYMBOL
## Description:
## Class Precedence List: (case in SBCL)
missing-symbol simple-error simple-condition program-error error serious-condition condition slot-object t
## Effective Slots:
FORMAT-CONTROL [Type] T
[READER] simple-condition-format-control
FORMAT-ARGUMENTS [Type] T
[READER] simple-condition-format-arguments
## Notes:
program-error
.
simple-error
.
Jump to: | A C D E F L M P S T |
---|
Jump to: | A C D E F L M P S T |
---|
Jump to: | A C F L M P S |
---|
Jump to: | A C F L M P S |
---|