aboutsummaryrefslogtreecommitdiffstats
path: root/doc/misc
diff options
context:
space:
mode:
authorStefan Monnier2015-04-13 14:36:55 -0400
committerStefan Monnier2015-04-13 14:36:55 -0400
commit8bab07bc03c7f51b64daecef0168eb11c2f5c1eb (patch)
treea8c67eb6ade144526ac578894d0a41ea6a23639c /doc/misc
parent5729f459d1dbb28bc405a142860a99e1329f388a (diff)
downloademacs-8bab07bc03c7f51b64daecef0168eb11c2f5c1eb.tar.gz
emacs-8bab07bc03c7f51b64daecef0168eb11c2f5c1eb.zip
* doc/misc/eieio.texi: Don't advertize now obsolete constructs
Diffstat (limited to 'doc/misc')
-rw-r--r--doc/misc/eieio.texi107
1 files changed, 32 insertions, 75 deletions
diff --git a/doc/misc/eieio.texi b/doc/misc/eieio.texi
index fe0b3265e84..5d1a8cf0702 100644
--- a/doc/misc/eieio.texi
+++ b/doc/misc/eieio.texi
@@ -140,13 +140,13 @@ constructor. The constructor is a function with the same name as your
140class which returns a new instance of that class. Here is an example: 140class which returns a new instance of that class. Here is an example:
141 141
142@example 142@example
143(setq rec (record "Eric" :name "Eric" :birthday "June" :phone "555-5555")) 143(setq rec (record :name "Eric" :birthday "June" :phone "555-5555"))
144@end example 144@end example
145 145
146@noindent 146@noindent
147The first argument is the name given to this instance. Each instance 147For backward compatibility reasons, the first argument can be a string (a name
148is given a name, so different instances can be easily distinguished 148given to this instance). Each instance used to be given a name, so different
149when debugging. 149instances could be easily distinguished when debugging.
150 150
151It can be a bit repetitive to also have a :name slot. To avoid doing 151It can be a bit repetitive to also have a :name slot. To avoid doing
152this, it is sometimes handy to use the base class @code{eieio-named}. 152this, it is sometimes handy to use the base class @code{eieio-named}.
@@ -244,7 +244,7 @@ EIEIO does not support it.
244This CLOS method tag is non-functional. 244This CLOS method tag is non-functional.
245 245
246@item :default-initargs in @code{defclass} 246@item :default-initargs in @code{defclass}
247Each slot has an @code{:initarg} tag, so this is not really necessary. 247Each slot can have an @code{:initform} tag, so this is not really necessary.
248 248
249@item Mock object initializers 249@item Mock object initializers
250Each class contains a mock object used for fast initialization of 250Each class contains a mock object used for fast initialization of
@@ -266,10 +266,9 @@ To create a new class, use the @code{defclass} macro:
266@defmac defclass class-name superclass-list slot-list &rest options-and-doc 266@defmac defclass class-name superclass-list slot-list &rest options-and-doc
267 267
268Create a new class named @var{class-name}. The class is represented 268Create a new class named @var{class-name}. The class is represented
269by a self-referential symbol with the name @var{class-name}. @eieio{} 269by a symbol with the name @var{class-name}. @eieio{} stores the structure of
270stores the structure of the class as a symbol property of 270the class as a symbol property of @var{class-name} (@pxref{Symbol
271@var{class-name} (@pxref{Symbol Components,,,elisp,GNU Emacs Lisp 271Components,,,elisp,GNU Emacs Lisp Reference Manual}).
272Reference Manual}).
273 272
274The @var{class-name} symbol's variable documentation string is a 273The @var{class-name} symbol's variable documentation string is a
275modified version of the doc string found in @var{options-and-doc}. 274modified version of the doc string found in @var{options-and-doc}.
@@ -292,17 +291,12 @@ or @code{:protection}.
292@end defmac 291@end defmac
293 292
294@noindent 293@noindent
295Whenever defclass is used to create a new class, two predicates are 294Whenever defclass is used to create a new class, a predicate is
296created for it, named @code{@var{CLASS-NAME}-p} and 295created for it, named @code{@var{CLASS-NAME}-p}:
297@code{@var{CLASS-NAME}-child-p}:
298 296
299@defun CLASS-NAME-p object 297@defun CLASS-NAME-p object
300Return @code{t} if @var{OBJECT} is of the class @var{CLASS-NAME}. 298Return non-@code{nil} if and only if @var{OBJECT} is of the class
301@end defun 299@var{CLASS-NAME}.
302
303@defun CLASS-NAME-child-p object
304Return @code{t} if @var{OBJECT} is of the class @var{CLASS-NAME},
305or is of a subclass of @var{CLASS-NAME}.
306@end defun 300@end defun
307 301
308@defvar eieio-error-unsupported-class-tags 302@defvar eieio-error-unsupported-class-tags
@@ -418,7 +412,7 @@ Valid tags are:
418@table @code 412@table @code
419@item :initarg 413@item :initarg
420A symbol that can be used in the argument list of the constructor to 414A symbol that can be used in the argument list of the constructor to
421specify a value for the new instance being created. 415specify a value for this slot of the new instance being created.
422 416
423A good symbol to use for initarg is one that starts with a colon @code{:}. 417A good symbol to use for initarg is one that starts with a colon @code{:}.
424 418
@@ -428,13 +422,13 @@ The slot specified like this:
428@end example 422@end example
429could then be initialized to the number 1 like this: 423could then be initialized to the number 1 like this:
430@example 424@example
431 (myobject "name" :myslot 1) 425 (myobject :myslot 1)
432@end example 426@end example
433 427
434@xref{Making New Objects}. 428@xref{Making New Objects}.
435 429
436@item :initform 430@item :initform
437A expression used as the default value for this slot. 431An expression used as the default value for this slot.
438 432
439If @code{:initform} is left out, that slot defaults to being unbound. 433If @code{:initform} is left out, that slot defaults to being unbound.
440It is an error to reference an unbound slot, so if you need 434It is an error to reference an unbound slot, so if you need
@@ -445,19 +439,13 @@ Use @code{slot-boundp} to test if a slot is unbound
445(@pxref{Predicates}). Use @code{slot-makeunbound} to set a slot to 439(@pxref{Predicates}). Use @code{slot-makeunbound} to set a slot to
446being unbound after giving it a value (@pxref{Accessing Slots}). 440being unbound after giving it a value (@pxref{Accessing Slots}).
447 441
448The value passed to initform is automatically quoted. Thus, 442The value passed to initform used to be automatically quoted. Thus,
449@example 443@example
450:initform (1 2 3) 444:initform (1 2 3)
451@end example 445@end example
452appears as the specified list in the default object. 446will use the list as a value. This is incompatible with CLOS (which would
453A symbol that is a function like this: 447signal an error since 1 is not a valid function) and will likely change in the
454@example 448future, so better quote your initforms if they're just values.
455:initform +
456@end example
457will set the initial value as that symbol.
458
459After a class has been created with @code{defclass}, you can change
460that default value with @code{oset-default}. @ref{Accessing Slots}.
461 449
462@item :type 450@item :type
463An unquoted type specifier used to validate data set into this slot. 451An unquoted type specifier used to validate data set into this slot.
@@ -669,7 +657,7 @@ can do any valid Lispy thing you want with it, such as
669Example of creating an object from a class: 657Example of creating an object from a class:
670 658
671@example 659@example
672(record "test" :value 3 :reference nil) 660(record :value 3 :reference nil)
673@end example 661@end example
674 662
675@end defun 663@end defun
@@ -692,15 +680,6 @@ for each slot. For example:
692 (make-instance @code{'foo} @code{:slot1} value1 @code{:slotN} valueN) 680 (make-instance @code{'foo} @code{:slot1} value1 @code{:slotN} valueN)
693@end example 681@end example
694 682
695Compatibility note:
696
697If the first element of @var{initargs} is a string, it is used as the
698name of the class.
699
700In @eieio{}, the class' constructor requires a name for use when printing.
701@dfn{make-instance} in CLOS doesn't use names the way Emacs does, so the
702class is used as the name slot instead when @var{initargs} doesn't start with
703a string.
704@end defun 683@end defun
705 684
706@node Accessing Slots 685@node Accessing Slots
@@ -717,14 +696,9 @@ This macro sets the value behind @var{slot} to @var{value} in
717@end defmac 696@end defmac
718 697
719@defmac oset-default class slot value 698@defmac oset-default class slot value
720This macro sets the @code{:initform} for @var{slot} in @var{class} to 699This macro sets the value for the class-allocated @var{slot} in @var{class} to
721@var{value}. 700@var{value}.
722 701
723This allows the user to set both public and private defaults after the
724class has been constructed, and provides a way to configure the
725default behavior of packages built with classes (the same way
726@code{setq-default} does for buffer-local variables).
727
728For example, if a user wanted all @code{data-objects} (@pxref{Building 702For example, if a user wanted all @code{data-objects} (@pxref{Building
729Classes}) to inform a special object of his own devising when they 703Classes}) to inform a special object of his own devising when they
730changed, this can be arranged by simply executing this bit of code: 704changed, this can be arranged by simply executing this bit of code:
@@ -737,16 +711,12 @@ changed, this can be arranged by simply executing this bit of code:
737@defmac oref obj slot 711@defmac oref obj slot
738@anchor{oref} 712@anchor{oref}
739Retrieve the value stored in @var{obj} in the slot named by @var{slot}. 713Retrieve the value stored in @var{obj} in the slot named by @var{slot}.
740Slot is the name of the slot when created by @dfn{defclass} or the label 714Slot is the name of the slot when created by @dfn{defclass}.
741created by the @code{:initarg} tag.
742@end defmac 715@end defmac
743 716
744@defmac oref-default obj slot 717@defmac oref-default class slot
745@anchor{oref-default} 718@anchor{oref-default}
746Gets the default value of @var{obj} (maybe a class) for @var{slot}. 719Get the value of the class-allocated @var{slot} from @var{class}.
747The default value is the value installed in a class with the @code{:initform}
748tag. @var{slot} can be the slot name, or the tag specified by the @code{:initarg}
749tag in the @dfn{defclass} call.
750@end defmac 720@end defmac
751 721
752The following accessors are defined by CLOS to reference or modify 722The following accessors are defined by CLOS to reference or modify
@@ -812,7 +782,7 @@ Where each @var{var} is the local variable given to the associated
812variable name of the same name as the slot. 782variable name of the same name as the slot.
813 783
814@example 784@example
815(defclass myclass () (x :initarg 1)) 785(defclass myclass () (x :initform 1))
816(setq mc (make-instance 'myclass)) 786(setq mc (make-instance 'myclass))
817(with-slots (x) mc x) => 1 787(with-slots (x) mc x) => 1
818(with-slots ((something x)) mc something) => 1 788(with-slots ((something x)) mc something) => 1
@@ -986,15 +956,14 @@ allows the first argument to be cast.
986@section Static Methods 956@section Static Methods
987 957
988Static methods do not depend on an object instance, but instead 958Static methods do not depend on an object instance, but instead
989operate on an object's class. You can create a static method by using 959operate on a class. You can create a static method by using
990the @code{:static} key with @code{defmethod}. 960the @code{:static} key with @code{defmethod}.
991 961
992Do not treat the first argument of a @code{:static} method as an 962The first argument of a @code{:static} method will be a class rather than an
993object unless you test it first. Use the functions 963object. Use the functions @code{oref-default} or @code{oset-default} which
994@code{oref-default} or @code{oset-default} which will work on a class, 964will work on a class.
995or on the class of an object.
996 965
997A Class' @code{constructor} method is defined as a @code{:static} 966A class's @code{make-instance} method is defined as a @code{:static}
998method. 967method.
999 968
1000@b{Note:} The @code{:static} keyword is unique to @eieio{}. 969@b{Note:} The @code{:static} keyword is unique to @eieio{}.
@@ -1085,13 +1054,6 @@ For example:
1085Will fetch the documentation string for @code{eieio-default-superclass}. 1054Will fetch the documentation string for @code{eieio-default-superclass}.
1086@end defun 1055@end defun
1087 1056
1088@defun class-constructor class
1089Return a symbol used as a constructor for @var{class}. The
1090constructor is a function used to create new instances of
1091@var{CLASS}. This function provides a way to make an object of a class
1092without knowing what it is. This is not a part of CLOS.
1093@end defun
1094
1095@defun eieio-object-name obj 1057@defun eieio-object-name obj
1096Return a string of the form @samp{#<object-class myobjname>} for @var{obj}. 1058Return a string of the form @samp{#<object-class myobjname>} for @var{obj}.
1097This should look like Lisp symbols from other parts of Emacs such as 1059This should look like Lisp symbols from other parts of Emacs such as
@@ -1105,11 +1067,6 @@ information into the symbol.
1105Returns the class symbol from @var{obj}. 1067Returns the class symbol from @var{obj}.
1106@end defun 1068@end defun
1107 1069
1108@defun eieio--object-class obj
1109Same as @code{eieio-object-class} except this is a macro, and no
1110type-checking is performed.
1111@end defun
1112
1113@defun eieio-object-class-name obj 1070@defun eieio-object-class-name obj
1114Returns the symbol of @var{obj}'s class. 1071Returns the symbol of @var{obj}'s class.
1115@end defun 1072@end defun
@@ -1267,7 +1224,7 @@ Return the list of public slots for @var{obj}.
1267@end defun 1224@end defun
1268 1225
1269@defun class-slot-initarg class slot 1226@defun class-slot-initarg class slot
1270For the given @var{class} return the :initarg associated with 1227For the given @var{class} return an :initarg associated with
1271@var{slot}. Not all slots have initargs, so the return value can be 1228@var{slot}. Not all slots have initargs, so the return value can be
1272@code{nil}. 1229@code{nil}.
1273@end defun 1230@end defun
@@ -1612,7 +1569,7 @@ is a list of name/value pairs. These are actually just passed to
1612Sets slots of @var{obj} with @var{slots} which is a list of name/value 1569Sets slots of @var{obj} with @var{slots} which is a list of name/value
1613pairs. 1570pairs.
1614 1571
1615This is called from the default @code{constructor}. 1572This is called from the default constructor.
1616@end defun 1573@end defun
1617 1574
1618@node Basic Methods 1575@node Basic Methods