eieio: Basic Methods
15.2 Basic Methods
==================
Additional useful methods defined on the base subclass are:
-- Function: clone obj &rest params
Make a copy of OBJ, and then apply PARAMS. PARAMS is a parameter
list of the same form as INITIALIZE-INSTANCE which are applied to
change the object. When overloading “clone”, be sure to call
“call-next-method” first and modify the returned object.
-- Function: object-print this &rest strings
Pretty printer for object THIS. Call function “eieio-object-name”
with STRINGS. The default method for printing object THIS is to
use the function “eieio-object-name”.
It is sometimes useful to put a summary of the object into the
default #<notation> string when using eieio browsing tools.
Implement this function and specify STRINGS in a call to
“call-next-method” to provide additional summary information. When
passing in extra strings from child classes, always remember to
prepend a space.
(defclass data-object ()
(value)
"Object containing one data slot.")
(defmethod object-print ((this data-object) &optional strings)
"Return a string with a summary of the data object as part of the name."
(apply 'call-next-method this
(cons (format " value: %s" (render this)) strings)))
Here is what some output could look like:
(object-print test-object)
=> #<data-object test-object value: 3>
-- Function: object-write obj &optional comment
Write OBJ onto a stream in a readable fashion. The resulting
output will be Lisp code which can be used with ‘read’ and ‘eval’
to recover the object. Only slots with ‘:initarg’s are written to
the stream.