|
Practical Common LispIn this case, the applicable method will be one provided by the implementation, specialized on STANDARD-OBJECT. Since not every object can be printed so that it can be read back, the STANDARD-OBJECT print method uses the #<> syntax, which will cause the reader to signal an error if it tries to read it. The rest of the representation is implementation-defined but will typically be something like the output just shown, including the name of the class and some distinguishing value such as the address of the object in memory. In Chapter 23 you'll see an example of how to define a method on PRINT-OBJECT to make objects of a certain class be printed in a more informative form. Using the definition of bank-account just given, new objects will be created with their slots unbound. Any attempt to get the value of an unbound slot signals an error, so you must set a slot before you can read it. (defparameter *account* (make-instance 'bank-account)) ==> *ACCOUNT* (setf (slot-value *account* 'customer-name) "John Doe") ==> "John Doe" (setf (slot-value *account* 'balance) 1000) ==> 1000 Now you can access the value of the slots. (slot-value *account* 'customer-name) ==> "John Doe" (slot-value *account* 'balance) ==> 1000 Object Initialization Since you can't do much with an object with unbound slots, it'd be nice to be able to create objects with their slots already initialized ...» | Код для вставки книги в блог HTML
phpBB
текст
|
|