Next: , Previous: Initialization, Up: Default Superclass

16.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 object-name with strings. The default method for printing object this is to use the function 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 :initargs are written to the stream.