diff options
| author | Stefan Monnier | 2015-04-13 14:36:55 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2015-04-13 14:36:55 -0400 |
| commit | 8bab07bc03c7f51b64daecef0168eb11c2f5c1eb (patch) | |
| tree | a8c67eb6ade144526ac578894d0a41ea6a23639c /doc/misc | |
| parent | 5729f459d1dbb28bc405a142860a99e1329f388a (diff) | |
| download | emacs-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.texi | 107 |
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 | |||
| 140 | class which returns a new instance of that class. Here is an example: | 140 | class 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 |
| 147 | The first argument is the name given to this instance. Each instance | 147 | For backward compatibility reasons, the first argument can be a string (a name |
| 148 | is given a name, so different instances can be easily distinguished | 148 | given to this instance). Each instance used to be given a name, so different |
| 149 | when debugging. | 149 | instances could be easily distinguished when debugging. |
| 150 | 150 | ||
| 151 | It can be a bit repetitive to also have a :name slot. To avoid doing | 151 | It can be a bit repetitive to also have a :name slot. To avoid doing |
| 152 | this, it is sometimes handy to use the base class @code{eieio-named}. | 152 | this, it is sometimes handy to use the base class @code{eieio-named}. |
| @@ -244,7 +244,7 @@ EIEIO does not support it. | |||
| 244 | This CLOS method tag is non-functional. | 244 | This CLOS method tag is non-functional. |
| 245 | 245 | ||
| 246 | @item :default-initargs in @code{defclass} | 246 | @item :default-initargs in @code{defclass} |
| 247 | Each slot has an @code{:initarg} tag, so this is not really necessary. | 247 | Each 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 |
| 250 | Each class contains a mock object used for fast initialization of | 250 | Each 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 | ||
| 268 | Create a new class named @var{class-name}. The class is represented | 268 | Create a new class named @var{class-name}. The class is represented |
| 269 | by a self-referential symbol with the name @var{class-name}. @eieio{} | 269 | by a symbol with the name @var{class-name}. @eieio{} stores the structure of |
| 270 | stores the structure of the class as a symbol property of | 270 | the class as a symbol property of @var{class-name} (@pxref{Symbol |
| 271 | @var{class-name} (@pxref{Symbol Components,,,elisp,GNU Emacs Lisp | 271 | Components,,,elisp,GNU Emacs Lisp Reference Manual}). |
| 272 | Reference Manual}). | ||
| 273 | 272 | ||
| 274 | The @var{class-name} symbol's variable documentation string is a | 273 | The @var{class-name} symbol's variable documentation string is a |
| 275 | modified version of the doc string found in @var{options-and-doc}. | 274 | modified 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 |
| 295 | Whenever defclass is used to create a new class, two predicates are | 294 | Whenever defclass is used to create a new class, a predicate is |
| 296 | created for it, named @code{@var{CLASS-NAME}-p} and | 295 | created 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 |
| 300 | Return @code{t} if @var{OBJECT} is of the class @var{CLASS-NAME}. | 298 | Return 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 | ||
| 304 | Return @code{t} if @var{OBJECT} is of the class @var{CLASS-NAME}, | ||
| 305 | or 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 |
| 420 | A symbol that can be used in the argument list of the constructor to | 414 | A symbol that can be used in the argument list of the constructor to |
| 421 | specify a value for the new instance being created. | 415 | specify a value for this slot of the new instance being created. |
| 422 | 416 | ||
| 423 | A good symbol to use for initarg is one that starts with a colon @code{:}. | 417 | A 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 |
| 429 | could then be initialized to the number 1 like this: | 423 | could 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 |
| 437 | A expression used as the default value for this slot. | 431 | An expression used as the default value for this slot. |
| 438 | 432 | ||
| 439 | If @code{:initform} is left out, that slot defaults to being unbound. | 433 | If @code{:initform} is left out, that slot defaults to being unbound. |
| 440 | It is an error to reference an unbound slot, so if you need | 434 | It 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 |
| 446 | being unbound after giving it a value (@pxref{Accessing Slots}). | 440 | being unbound after giving it a value (@pxref{Accessing Slots}). |
| 447 | 441 | ||
| 448 | The value passed to initform is automatically quoted. Thus, | 442 | The 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 |
| 452 | appears as the specified list in the default object. | 446 | will use the list as a value. This is incompatible with CLOS (which would |
| 453 | A symbol that is a function like this: | 447 | signal an error since 1 is not a valid function) and will likely change in the |
| 454 | @example | 448 | future, so better quote your initforms if they're just values. |
| 455 | :initform + | ||
| 456 | @end example | ||
| 457 | will set the initial value as that symbol. | ||
| 458 | |||
| 459 | After a class has been created with @code{defclass}, you can change | ||
| 460 | that default value with @code{oset-default}. @ref{Accessing Slots}. | ||
| 461 | 449 | ||
| 462 | @item :type | 450 | @item :type |
| 463 | An unquoted type specifier used to validate data set into this slot. | 451 | An 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 | |||
| 669 | Example of creating an object from a class: | 657 | Example 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 | ||
| 695 | Compatibility note: | ||
| 696 | |||
| 697 | If the first element of @var{initargs} is a string, it is used as the | ||
| 698 | name of the class. | ||
| 699 | |||
| 700 | In @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 | ||
| 702 | class is used as the name slot instead when @var{initargs} doesn't start with | ||
| 703 | a 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 |
| 720 | This macro sets the @code{:initform} for @var{slot} in @var{class} to | 699 | This macro sets the value for the class-allocated @var{slot} in @var{class} to |
| 721 | @var{value}. | 700 | @var{value}. |
| 722 | 701 | ||
| 723 | This allows the user to set both public and private defaults after the | ||
| 724 | class has been constructed, and provides a way to configure the | ||
| 725 | default behavior of packages built with classes (the same way | ||
| 726 | @code{setq-default} does for buffer-local variables). | ||
| 727 | |||
| 728 | For example, if a user wanted all @code{data-objects} (@pxref{Building | 702 | For example, if a user wanted all @code{data-objects} (@pxref{Building |
| 729 | Classes}) to inform a special object of his own devising when they | 703 | Classes}) to inform a special object of his own devising when they |
| 730 | changed, this can be arranged by simply executing this bit of code: | 704 | changed, 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} |
| 739 | Retrieve the value stored in @var{obj} in the slot named by @var{slot}. | 713 | Retrieve the value stored in @var{obj} in the slot named by @var{slot}. |
| 740 | Slot is the name of the slot when created by @dfn{defclass} or the label | 714 | Slot is the name of the slot when created by @dfn{defclass}. |
| 741 | created 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} |
| 746 | Gets the default value of @var{obj} (maybe a class) for @var{slot}. | 719 | Get the value of the class-allocated @var{slot} from @var{class}. |
| 747 | The default value is the value installed in a class with the @code{:initform} | ||
| 748 | tag. @var{slot} can be the slot name, or the tag specified by the @code{:initarg} | ||
| 749 | tag in the @dfn{defclass} call. | ||
| 750 | @end defmac | 720 | @end defmac |
| 751 | 721 | ||
| 752 | The following accessors are defined by CLOS to reference or modify | 722 | The 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 | |||
| 812 | variable name of the same name as the slot. | 782 | variable 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 | ||
| 988 | Static methods do not depend on an object instance, but instead | 958 | Static methods do not depend on an object instance, but instead |
| 989 | operate on an object's class. You can create a static method by using | 959 | operate on a class. You can create a static method by using |
| 990 | the @code{:static} key with @code{defmethod}. | 960 | the @code{:static} key with @code{defmethod}. |
| 991 | 961 | ||
| 992 | Do not treat the first argument of a @code{:static} method as an | 962 | The first argument of a @code{:static} method will be a class rather than an |
| 993 | object unless you test it first. Use the functions | 963 | object. 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, | 964 | will work on a class. |
| 995 | or on the class of an object. | ||
| 996 | 965 | ||
| 997 | A Class' @code{constructor} method is defined as a @code{:static} | 966 | A class's @code{make-instance} method is defined as a @code{:static} |
| 998 | method. | 967 | method. |
| 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: | |||
| 1085 | Will fetch the documentation string for @code{eieio-default-superclass}. | 1054 | Will fetch the documentation string for @code{eieio-default-superclass}. |
| 1086 | @end defun | 1055 | @end defun |
| 1087 | 1056 | ||
| 1088 | @defun class-constructor class | ||
| 1089 | Return a symbol used as a constructor for @var{class}. The | ||
| 1090 | constructor is a function used to create new instances of | ||
| 1091 | @var{CLASS}. This function provides a way to make an object of a class | ||
| 1092 | without 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 |
| 1096 | Return a string of the form @samp{#<object-class myobjname>} for @var{obj}. | 1058 | Return a string of the form @samp{#<object-class myobjname>} for @var{obj}. |
| 1097 | This should look like Lisp symbols from other parts of Emacs such as | 1059 | This should look like Lisp symbols from other parts of Emacs such as |
| @@ -1105,11 +1067,6 @@ information into the symbol. | |||
| 1105 | Returns the class symbol from @var{obj}. | 1067 | Returns the class symbol from @var{obj}. |
| 1106 | @end defun | 1068 | @end defun |
| 1107 | 1069 | ||
| 1108 | @defun eieio--object-class obj | ||
| 1109 | Same as @code{eieio-object-class} except this is a macro, and no | ||
| 1110 | type-checking is performed. | ||
| 1111 | @end defun | ||
| 1112 | |||
| 1113 | @defun eieio-object-class-name obj | 1070 | @defun eieio-object-class-name obj |
| 1114 | Returns the symbol of @var{obj}'s class. | 1071 | Returns 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 |
| 1270 | For the given @var{class} return the :initarg associated with | 1227 | For 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 | |||
| 1612 | Sets slots of @var{obj} with @var{slots} which is a list of name/value | 1569 | Sets slots of @var{obj} with @var{slots} which is a list of name/value |
| 1613 | pairs. | 1570 | pairs. |
| 1614 | 1571 | ||
| 1615 | This is called from the default @code{constructor}. | 1572 | This is called from the default constructor. |
| 1616 | @end defun | 1573 | @end defun |
| 1617 | 1574 | ||
| 1618 | @node Basic Methods | 1575 | @node Basic Methods |