diff options
| author | Gemini Lasswell | 2018-11-22 13:00:03 -0800 |
|---|---|---|
| committer | Noam Postavsky | 2019-04-09 18:53:43 -0400 |
| commit | 8d2f1df51aa02c101a3ce4655ff6ed6d2b64e4cf (patch) | |
| tree | 553b8d34817c1cb05627997ba0ca3b6e22d954fe | |
| parent | 00a2d57adfe78bd137cd9458d9133f9c825b7d75 (diff) | |
| download | emacs-8d2f1df51aa02c101a3ce4655ff6ed6d2b64e4cf.tar.gz emacs-8d2f1df51aa02c101a3ce4655ff6ed6d2b64e4cf.zip | |
Address name conflicts in EIEIO documentation (bug#31660)
* doc/misc/eieio.texi (Quick Start): Rename the class used in the
example from 'record' to 'person'.
(Building Classes): Advise user to check for name conflicts before
naming a class. Add a missing apostrophe.
(Making New Objects): Correct grammar. Rename the class used in the
example from 'record' to 'my-class'.
| -rw-r--r-- | doc/misc/eieio.texi | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/doc/misc/eieio.texi b/doc/misc/eieio.texi index d03ee79f18b..f56b2b67a40 100644 --- a/doc/misc/eieio.texi +++ b/doc/misc/eieio.texi | |||
| @@ -88,11 +88,11 @@ framework for writing object-oriented applications in Emacs. | |||
| 88 | use @eieio{} to create classes, methods for those classes, and | 88 | use @eieio{} to create classes, methods for those classes, and |
| 89 | instances of classes. | 89 | instances of classes. |
| 90 | 90 | ||
| 91 | Here is a simple example of a class named @code{record}, containing | 91 | Here is a simple example of a class named @code{person}, containing |
| 92 | three slots named @code{name}, @code{birthday}, and @code{phone}: | 92 | three slots named @code{name}, @code{birthday}, and @code{phone}: |
| 93 | 93 | ||
| 94 | @example | 94 | @example |
| 95 | (defclass record () ; No superclasses | 95 | (defclass person () ; No superclasses |
| 96 | ((name :initarg :name | 96 | ((name :initarg :name |
| 97 | :initform "" | 97 | :initform "" |
| 98 | :type string | 98 | :type string |
| @@ -106,23 +106,23 @@ three slots named @code{name}, @code{birthday}, and @code{phone}: | |||
| 106 | (phone :initarg :phone | 106 | (phone :initarg :phone |
| 107 | :initform "" | 107 | :initform "" |
| 108 | :documentation "Phone number.")) | 108 | :documentation "Phone number.")) |
| 109 | "A single record for tracking people I know.") | 109 | "A class for tracking people I know.") |
| 110 | @end example | 110 | @end example |
| 111 | 111 | ||
| 112 | Each class can have methods, which are defined like this: | 112 | Each class can have methods, which are defined like this: |
| 113 | 113 | ||
| 114 | @example | 114 | @example |
| 115 | (cl-defmethod call-record ((rec record) &optional scriptname) | 115 | (cl-defmethod call-person ((pers person) &optional scriptname) |
| 116 | "Dial the phone for the record REC. | 116 | "Dial the phone for the person PERS. |
| 117 | Execute the program SCRIPTNAME to dial the phone." | 117 | Execute the program SCRIPTNAME to dial the phone." |
| 118 | (message "Dialing the phone for %s" (oref rec name)) | 118 | (message "Dialing the phone for %s" (oref pers name)) |
| 119 | (shell-command (concat (or scriptname "dialphone.sh") | 119 | (shell-command (concat (or scriptname "dialphone.sh") |
| 120 | " " | 120 | " " |
| 121 | (oref rec phone)))) | 121 | (oref pers phone)))) |
| 122 | @end example | 122 | @end example |
| 123 | 123 | ||
| 124 | @noindent | 124 | @noindent |
| 125 | In this example, the first argument to @code{call-record} is a list, | 125 | In this example, the first argument to @code{call-person} is a list, |
| 126 | of the form (@var{varname} @var{classname}). @var{varname} is the | 126 | of the form (@var{varname} @var{classname}). @var{varname} is the |
| 127 | name of the variable used for the first argument; @var{classname} is | 127 | name of the variable used for the first argument; @var{classname} is |
| 128 | the name of the class that is expected as the first argument for this | 128 | the name of the class that is expected as the first argument for this |
| @@ -130,17 +130,17 @@ method. | |||
| 130 | 130 | ||
| 131 | @eieio{} dispatches methods based on the type of the first argument. | 131 | @eieio{} dispatches methods based on the type of the first argument. |
| 132 | You can have multiple methods with the same name for different classes | 132 | You can have multiple methods with the same name for different classes |
| 133 | of object. When the @code{call-record} method is called, the first | 133 | of object. When the @code{call-person} method is called, the first |
| 134 | argument is examined to determine the class of that argument, and the | 134 | argument is examined to determine the class of that argument, and the |
| 135 | method matching the input type is then executed. | 135 | method matching the input type is then executed. |
| 136 | 136 | ||
| 137 | Once the behavior of a class is defined, you can create a new | 137 | Once the behavior of a class is defined, you can create a new |
| 138 | object of type @code{record}. Objects are created by calling the | 138 | object of type @code{person}. Objects are created by calling the |
| 139 | constructor. The constructor is a function with the same name as your | 139 | 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 :name "Eric" :birthday "June" :phone "555-5555")) | 143 | (setq pers (person :name "Eric" :birthday "June" :phone "555-5555")) |
| 144 | @end example | 144 | @end example |
| 145 | 145 | ||
| 146 | @noindent | 146 | @noindent |
| @@ -157,19 +157,19 @@ first argument should be an object of a class which has had this | |||
| 157 | method defined for it. In this example it would look like this: | 157 | method defined for it. In this example it would look like this: |
| 158 | 158 | ||
| 159 | @example | 159 | @example |
| 160 | (call-record rec) | 160 | (call-person pers) |
| 161 | @end example | 161 | @end example |
| 162 | 162 | ||
| 163 | @noindent | 163 | @noindent |
| 164 | or | 164 | or |
| 165 | 165 | ||
| 166 | @example | 166 | @example |
| 167 | (call-record rec "my-call-script") | 167 | (call-person pers "my-call-script") |
| 168 | @end example | 168 | @end example |
| 169 | 169 | ||
| 170 | In these examples, @eieio{} automatically examines the class of | 170 | In these examples, @eieio{} automatically examines the class of |
| 171 | @code{rec}, and ensures that the method defined above is called. If | 171 | @code{pers}, and ensures that the method defined above is called. If |
| 172 | @code{rec} is some other class lacking a @code{call-record} method, or | 172 | @code{pers} is some other class lacking a @code{call-person} method, or |
| 173 | some other data type, Emacs signals a @code{cl-no-applicable-method} | 173 | some other data type, Emacs signals a @code{cl-no-applicable-method} |
| 174 | error. @ref{Signals}. | 174 | error. @ref{Signals}. |
| 175 | 175 | ||
| @@ -270,10 +270,18 @@ by a symbol with the name @var{class-name}. @eieio{} stores the structure of | |||
| 270 | the class as a symbol property of @var{class-name} (@pxref{Symbol | 270 | the class as a symbol property of @var{class-name} (@pxref{Symbol |
| 271 | Components,,,elisp,GNU Emacs Lisp Reference Manual}). | 271 | Components,,,elisp,GNU Emacs Lisp Reference Manual}). |
| 272 | 272 | ||
| 273 | When defining a class, @eieio{} overwrites any preexisting variable or | ||
| 274 | function bindings for the symbol @var{class-name}, which may lead to | ||
| 275 | undesired consequences. Before naming a new class, you should check | ||
| 276 | for name conflicts. To help avoid cross-package conflicts you should | ||
| 277 | choose a name with the same prefix you chose for the rest of your | ||
| 278 | package's functions and variables (@pxref{Coding | ||
| 279 | Conventions,,,elisp,GNU Emacs Lisp Reference Manual}). | ||
| 280 | |||
| 273 | The @var{class-name} symbol's variable documentation string is a | 281 | The @var{class-name} symbol's variable documentation string is a |
| 274 | modified version of the doc string found in @var{options-and-doc}. | 282 | modified version of the doc string found in @var{options-and-doc}. |
| 275 | Each time a method is defined, the symbol's documentation string is | 283 | Each time a method is defined, the symbol's documentation string is |
| 276 | updated to include the methods documentation as well. | 284 | updated to include the method's documentation as well. |
| 277 | 285 | ||
| 278 | The parent classes for @var{class-name} is @var{superclass-list}. | 286 | The parent classes for @var{class-name} is @var{superclass-list}. |
| 279 | Each element of @var{superclass-list} must be a class. These classes | 287 | Each element of @var{superclass-list} must be a class. These classes |
| @@ -625,10 +633,10 @@ function of @code{:initform}. | |||
| 625 | @node Making New Objects | 633 | @node Making New Objects |
| 626 | @chapter Making New Objects | 634 | @chapter Making New Objects |
| 627 | 635 | ||
| 628 | Suppose we have a simple class is defined, such as: | 636 | Suppose we have defined a simple class, such as: |
| 629 | 637 | ||
| 630 | @example | 638 | @example |
| 631 | (defclass record () | 639 | (defclass my-class () |
| 632 | ( ) "Doc String") | 640 | ( ) "Doc String") |
| 633 | @end example | 641 | @end example |
| 634 | 642 | ||
| @@ -636,10 +644,10 @@ Suppose we have a simple class is defined, such as: | |||
| 636 | It is now possible to create objects of that class type. | 644 | It is now possible to create objects of that class type. |
| 637 | 645 | ||
| 638 | Calling @code{defclass} has defined two new functions. One is the | 646 | Calling @code{defclass} has defined two new functions. One is the |
| 639 | constructor @var{record}, and the other is the predicate, | 647 | constructor @var{my-class}, and the other is the predicate, |
| 640 | @var{record}-p. | 648 | @var{my-class}-p. |
| 641 | 649 | ||
| 642 | @defun record object-name &rest slots | 650 | @defun my-class object-name &rest slots |
| 643 | 651 | ||
| 644 | This creates and returns a new object. This object is not assigned to | 652 | This creates and returns a new object. This object is not assigned to |
| 645 | anything, and will be garbage collected if not saved. This object | 653 | anything, and will be garbage collected if not saved. This object |
| @@ -657,7 +665,7 @@ can do any valid Lispy thing you want with it, such as | |||
| 657 | Example of creating an object from a class: | 665 | Example of creating an object from a class: |
| 658 | 666 | ||
| 659 | @example | 667 | @example |
| 660 | (record :value 3 :reference nil) | 668 | (my-class :value 3 :reference nil) |
| 661 | @end example | 669 | @end example |
| 662 | 670 | ||
| 663 | @end defun | 671 | @end defun |