aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGemini Lasswell2018-11-22 13:00:03 -0800
committerNoam Postavsky2019-04-09 18:53:43 -0400
commit8d2f1df51aa02c101a3ce4655ff6ed6d2b64e4cf (patch)
tree553b8d34817c1cb05627997ba0ca3b6e22d954fe
parent00a2d57adfe78bd137cd9458d9133f9c825b7d75 (diff)
downloademacs-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.texi52
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.
88use @eieio{} to create classes, methods for those classes, and 88use @eieio{} to create classes, methods for those classes, and
89instances of classes. 89instances of classes.
90 90
91Here is a simple example of a class named @code{record}, containing 91Here is a simple example of a class named @code{person}, containing
92three slots named @code{name}, @code{birthday}, and @code{phone}: 92three 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
112Each class can have methods, which are defined like this: 112Each 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.
117Execute the program SCRIPTNAME to dial the phone." 117Execute 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
125In this example, the first argument to @code{call-record} is a list, 125In this example, the first argument to @code{call-person} is a list,
126of the form (@var{varname} @var{classname}). @var{varname} is the 126of the form (@var{varname} @var{classname}). @var{varname} is the
127name of the variable used for the first argument; @var{classname} is 127name of the variable used for the first argument; @var{classname} is
128the name of the class that is expected as the first argument for this 128the 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.
132You can have multiple methods with the same name for different classes 132You can have multiple methods with the same name for different classes
133of object. When the @code{call-record} method is called, the first 133of object. When the @code{call-person} method is called, the first
134argument is examined to determine the class of that argument, and the 134argument is examined to determine the class of that argument, and the
135method matching the input type is then executed. 135method matching the input type is then executed.
136 136
137Once the behavior of a class is defined, you can create a new 137Once the behavior of a class is defined, you can create a new
138object of type @code{record}. Objects are created by calling the 138object of type @code{person}. Objects are created by calling the
139constructor. The constructor is a function with the same name as your 139constructor. 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 :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
157method defined for it. In this example it would look like this: 157method 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
164or 164or
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
170In these examples, @eieio{} automatically examines the class of 170In 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
173some other data type, Emacs signals a @code{cl-no-applicable-method} 173some other data type, Emacs signals a @code{cl-no-applicable-method}
174error. @ref{Signals}. 174error. @ref{Signals}.
175 175
@@ -270,10 +270,18 @@ by a symbol with the name @var{class-name}. @eieio{} stores the structure of
270the class as a symbol property of @var{class-name} (@pxref{Symbol 270the class as a symbol property of @var{class-name} (@pxref{Symbol
271Components,,,elisp,GNU Emacs Lisp Reference Manual}). 271Components,,,elisp,GNU Emacs Lisp Reference Manual}).
272 272
273When defining a class, @eieio{} overwrites any preexisting variable or
274function bindings for the symbol @var{class-name}, which may lead to
275undesired consequences. Before naming a new class, you should check
276for name conflicts. To help avoid cross-package conflicts you should
277choose a name with the same prefix you chose for the rest of your
278package's functions and variables (@pxref{Coding
279Conventions,,,elisp,GNU Emacs Lisp Reference Manual}).
280
273The @var{class-name} symbol's variable documentation string is a 281The @var{class-name} symbol's variable documentation string is a
274modified version of the doc string found in @var{options-and-doc}. 282modified version of the doc string found in @var{options-and-doc}.
275Each time a method is defined, the symbol's documentation string is 283Each time a method is defined, the symbol's documentation string is
276updated to include the methods documentation as well. 284updated to include the method's documentation as well.
277 285
278The parent classes for @var{class-name} is @var{superclass-list}. 286The parent classes for @var{class-name} is @var{superclass-list}.
279Each element of @var{superclass-list} must be a class. These classes 287Each 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
628Suppose we have a simple class is defined, such as: 636Suppose 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:
636It is now possible to create objects of that class type. 644It is now possible to create objects of that class type.
637 645
638Calling @code{defclass} has defined two new functions. One is the 646Calling @code{defclass} has defined two new functions. One is the
639constructor @var{record}, and the other is the predicate, 647constructor @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
644This creates and returns a new object. This object is not assigned to 652This creates and returns a new object. This object is not assigned to
645anything, and will be garbage collected if not saved. This object 653anything, 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
657Example of creating an object from a class: 665Example 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