[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple-view



At  1:44 PM 2/24/93 -0500, Jiqian Pan wrote:
 >Hi, MCL experts:
 >
 >I made an instance of the class SIMPLE-VIEW.  Here is a list of
 >what I have done:
 >
 >? (setf my-view (make-instance 'simple-view))
 >#<SIMPLE-VIEW #x8AA4C9>
 >
 >I wonder why I can use VIEW-FONT to MY-VIEW, but not DIRECTION.
 >The manual of MCL (pp.127) does not mention the slots DIRECTION
 >and VIEW-ALIST.  What functions are the two slots?
 >
 >Thanks for your help in advance.
 >
 >- J. Pan

This is because of a wonderful feature of lisp. The name of the slot
is not necessarily the name of the function which reads that slot.

For example, you could have a CLOS object called CITY with a slot called MAP.
But you wouldn't want MAP to be the name of the function which gets the
slot's value, because lisp already has another function called "MAP" which
does something very different. So, you might want to use "CITY-MAP" instead
to read the MAP slot of a CITY object. Here's an example of such a definition,
using the :ACCESSOR slot option:

(defclass city ()
   ((map :initform nil :initarg :map :accessor city-map)
    (population :initform nil :initarg :population :accessor city-population)
    (name :initform nil :initarg :name :accessor city-name))

In the case of simple-views, since they are actually streams, you can use
the function STREAM-DIRECTION to read the direction slot. 

In the general case, you can read any slot of a CLOS object by using the
SLOT-VALUE function. In general, it's considered good style to avoid
using SLOT-VALUE when another accessor function is provided, because it's
more of a low-level function.


? (setq xx (make-instance 'simple-view))
#<simple-view #x123ED19>
? (stream-direction xx)
:output
? (slot-value xx 'direction)
:output