home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / language / xlisp2_1 / xloop.doc < prev    next >
Encoding:
Internet Message Format  |  1993-10-23  |  22.0 KB

  1. Path: hplabsz!hplabs!hpfcso!hpfcbig!tim
  2. From: tim@hpfcbig.SDE.HP.COM (Tim Mikkelsen)
  3. Newsgroups: comp.lang.lisp.x
  4. Subject: Re: intro to XLISP objects
  5. Message-ID: <1170005@hpfcbig.SDE.HP.COM>
  6. Date: 12 Feb 90 16:23:48 GMT
  7. References: <1170004@hpfcbig.SDE.HP.COM>
  8. Organization: HP SESD, Fort Collins, CO
  9. Lines: 434
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.                XLISP 2.0 OBJECTS PRIMER
  23.  
  24.  
  25.                      by 
  26.  
  27.                    Tim I Mikkelsen
  28.  
  29.  
  30.                   February 3, 1990
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.     Copyright  (c) 1990 by Tim I.  Mikkelsen.  All Rights  Reserved.
  40.     No part of this document may be copied, reproduced or translated
  41.     for commercial use without prior written  consent of the author.
  42.     Permission  is granted  for  non-commercial  use as long as this
  43.     notice is left intact.
  44.  
  45.  
  46.     ________________________________________________________________
  47.  
  48.     
  49.     One of the  features  in the design of XLISP is  object-oriented
  50.     programming.  This  primer is  intended to serve as a very brief
  51.     introduction  to the object  facilities of the XLISP 2.0 dialect
  52.     of LISP.  Note that the object  features  of XLISP are not based
  53.     on other existing object definitions in other LISP dialects.  If
  54.     you find problems in the primer, I'd appreciate hearing.
  55.  
  56.  
  57.             Tim Mikkelsen
  58.             4316 Picadilly Drive
  59.             Fort Collins, Colorado  80526
  60.  
  61.  
  62.  
  63. PROGRAMMING STYLES
  64. ______________________________________________________________________________
  65.  
  66.  
  67. There are many  programming  paradigms  (models).  Some of the paradigms
  68. are procedural, functional, rule-based, declarative and object-oriented.
  69. A language can have aspects of one or many of these programming  models.
  70.  
  71.  
  72. Procedure-Oriented
  73.  
  74. The programming paradigm most people are familiar with is the procedural
  75. style.  The primitives in procedural  programming  are:  subroutines and
  76. data  structures.  Through  these  primitives,   programmers  have  some
  77. limited abilities to share programs and program fragments.  C and Pascal
  78. are examples of procedural  languages.  Some procedural  languages (such
  79. as Modula and ADA) have  extensions  that provide for better  sharing of
  80. code.
  81.  
  82.  
  83. Object-Oriented Programming
  84.  
  85. Object-oriented  programming  is based  on the  primitives  of  objects,
  86. classes and messages.  Objects are defined in terms of classes.  Actions
  87. occur by sending a message to an object.  An object's  definition can be
  88. inherited  from  more  general  classes.  Objective-C  and C++ both  are
  89. object-oriented  dialects of the C language.  Many dialects of LISP have
  90. some object oriented extension (Flavors, Common LOOPS, CLOS and others).
  91. There  currently is standards  work  proceeding  to add  object-oriented
  92. programming to Common LISP.
  93.  
  94.  
  95. Object Oriented Programming
  96.  
  97. So, the  object-oriented  programming model is based around the concepts
  98. of objects,  classes and messages.  An object is essentially a black box
  99. that contains internal state  information.  You send an object a message
  100. which causes the object to perform some  operation.  Objects are defined
  101. and described through classes.
  102.  
  103. One aspect of an object is that you do not have to know what is inside -
  104. or how it  works - to be able to use it.  From a  programming  point  of
  105. view,  this is very  handy.  You can  develop a series  of  objects  for
  106. someone to use.  If you need to change what goes on inside, the users of
  107. the objects should be unaware.
  108.  
  109. Another aspect of objects is that of  inheritance.  You can build up new
  110. classes  from  existing  classes  by  inheriting  the  existing  class's
  111. functionality  and then extending the new  definition.  For example, you
  112. can  define a tool class  (with  various  attributes)  and then go about
  113. creating  object  instances  tool-1,  tool-2,  and so on.  You can  also
  114. create new sub-classes of the tool class like  power-tool.  This is also
  115. very handy because you don't have to  re-implement  something if you can
  116. build it up from existing code.
  117.  
  118.  
  119.  
  120.  
  121. XLISP OBJECT-ORIENTED PROGRAMMING
  122. ______________________________________________________________________________
  123.  
  124.  
  125.  
  126. XLISP OBJECT TERMINOLOGY
  127.  
  128. There  are, as  previously  mentioned,  many  different  languages  with
  129. object-oriented  extensions and facilities.  The terminology, operations
  130. and  styles of these are very  different.  Some of the main  definitions
  131. for XLISP's object-oriented extensions are:
  132.  
  133.     Object data type        The OBJECT DATA TYPE is a built-in  data
  134.                 type of  XLISP.  Members  of the  object
  135.                 data  type  are  object   instances  and
  136.                 classes.
  137.  
  138.     Object instances        An  OBJECT   INSTANCE  is  a   composite
  139.                 structure that contains  internal  state
  140.                 information,  methods  (the  code  which
  141.                 respond to  messages),  a pointer to the
  142.                 object  instance's  defining class and a
  143.                 pointer  to  the  object's  super-class.
  144.                 XLISP   contains   no  built-in   object
  145.                 instances.
  146.  
  147.     Class objects           A  CLASS  OBJECT  is,  essentially,  the
  148.                 template for defining the derived object
  149.                 instances.  A  class  object,   although
  150.                 used  differently  from a simple  object
  151.                 instance,  is  structurally  a member of
  152.                 the  object   data   type.  It  is  also
  153.                 contains  the  linking   mechanism  that
  154.                 allows  you to build  class  hierarchies
  155.                 (sub-classes and  super-classes).  XLISP
  156.                 contains  two  built-in  class  objects:
  157.                 OBJECT and CLASS.
  158.  
  159.     Message selector        The MESSAGE  SELECTOR is the symbol that
  160.                 is used to  select a  particular  action
  161.                 (Method) from the object.
  162.  
  163.     Message                 The  MESSAGE is the  combination  of the
  164.                 message  selector  and the data (if any)
  165.                 to be sent to the object.
  166.  
  167.     Method                  The METHOD is the actual  code that gets
  168.                 executed  when the object  receives  the
  169.                 Message.
  170.  
  171.  
  172.  
  173. SENDING MESSAGES
  174.  
  175. The  mechanism  for  sending  messages to XLISP  objects is via the SEND
  176. function.  It takes an object, a message  selector and various  optional
  177. arguments (depending on the message selector).
  178.  
  179. The way that a user  creates a new object is to send a :NEW message to a
  180. previously  defined  class.  The  result  of this  SEND will  return  an
  181. object, so this is normally preceded by a SETQ.  The values shown in the
  182. examples  that follow may not match what you see if you try this on your
  183. version of XLISP - this is not an error.  The  screens  that are used in
  184. the various examples are similar to what you should see on your computer
  185. screen.  The ">" is the normal XLISP prompt (the  characters that follow
  186. the prompt is what you should type in to try these examples).
  187.  
  188.  
  189.      ________________________________________________________________
  190.     |
  191.     |    > (setq my-object (send object :new))
  192.     |    #<Object: #2e100>
  193.     |________________________________________________________________
  194.  
  195.  
  196. The object  created here is of limited  value.  Most often, you create a
  197. class  object and then you create  instances  of that  class.  So in the
  198. following  example, a class called MY-CLASS is created that inherits its
  199. definition from the a built-in CLASS definition.  Then two instances are
  200. created of the new class.
  201.  
  202.      ________________________________________________________________
  203.     |
  204.     |    > (setq my-class (send class :new '()))
  205.     |    #<Object: #27756>
  206.     |    
  207.     |    > (setq my-instance (send my-class :new))
  208.     |    #<Object: #27652>
  209.     |
  210.     |    > (setq another-instance (send my-class :new))
  211.     |#<Object: #275da>
  212.     |________________________________________________________________
  213.  
  214.  
  215.  
  216. CLASSES
  217.  
  218. Previously,  a :NEW  message was used to create an object.  The  message
  219. used to see what is in an object is the :SHOW message.
  220.  
  221.      ________________________________________________________________
  222.     |
  223.     |    > (send my-class :show)
  224.     |    Object is #<Object: #27756>, Class is #<Object: #23fe2>
  225.     |      MESSAGES = NIL
  226.     |      IVARS = NIL
  227.     |      CVARS = NIL
  228.     |      CVALS = NIL
  229.     |      SUPERCLASS = #<Object: #23fd8>
  230.     |      IVARCNT = 0
  231.     |      IVARTOTAL = 0
  232.     |    #<Object: #27756>
  233.     |________________________________________________________________
  234.  
  235.  
  236. From the display of the MY-CLASS  object you can see there are a variety
  237. of components.  The components of a class are:
  238.  
  239.     Class Pointer           This  pointer  shows to what  class  the
  240.                 object (instance or class) belongs.  For
  241.                 a  class,  this  always  points  to  the
  242.                 built-in  object  CLASS.  This  is  also
  243.                 true  of the  CLASS  object,  its  class
  244.                 pointer points to itself.
  245.  
  246.     Superclass Pointer      This  pointer  shows what the next class
  247.                 up the class  hierarchy is.  If the user
  248.                 does  not  specify  what  class  is  the
  249.                 superclass,   it  will   point   to  the
  250.                 built-in class OBJECT.
  251.  
  252.     Messages                This  component  shows what messages are
  253.                 allowed   for   the   class,   and   the
  254.                 description  of the method  that will be
  255.                 used.  If the method is  system-defined,
  256.                 it will show up in the form of '#<Subr-:
  257.                 #18b98>'.  Remember   that   the   class
  258.                 hierarchy    (through   the   Superclass
  259.                 Pointer) is  searched  if the  requested
  260.                 message is not found in the class.
  261.  
  262.     Instance Variables      This   component   lists  what  instance
  263.                 variables will be created when an object
  264.                 instance is created.  If no instances of
  265.                 the class  exist,  there are no Instance
  266.                 Variables.  If there are 5 instances  of
  267.                 a  class,  there  are  5  complete   and
  268.                 different   groups   of   the   Instance
  269.                 Variables.
  270.  
  271.     Class Variables         The  CLASS  VARIABLES  (CVAR)  component
  272.     and Values        lists what class variables  exist within
  273.                 the  class.  The  Class  Values   (CVAL)
  274.                 component  shows what the current values
  275.                 of the variables  are.  Class  Variables
  276.                 are used to hold state information about
  277.                 a class.  There  will be |Bone of each|A
  278.                 of the Class  Variables,  independent of
  279.                 the  number of  instances  of the  class
  280.                 created.
  281.  
  282. A BETTER EXAMPLE
  283.  
  284. The  example  previously  shown  does work, but the class and  instances
  285. created  don't really do anything of  interest.  The  following  example
  286. sets up a tool class and creates some tool instances.
  287.  
  288.      ________________________________________________________________
  289.     |
  290.     |    > (setq my-tools (send class :new '(power moveable operation)))
  291.     |    #<Object: #277a6>
  292.     |
  293.     |    > (send my-tools :answer :isnew '(pow mov op) 
  294.     |                     '((setq power pow)
  295.     |                       (setq moveable mov)
  296.     |                       (setq operation op)))
  297.     |    #<Object: #277a6>
  298.     |
  299.     |    > (setq drill (send my-tools :new 'AC t 'holes))
  300.     |    #<Object: #2ddbc>
  301.     |
  302.     |    > (setq hand-saw (send my-tools :new 'none t 'cuts))
  303.     |    #<Object: #2dc40>
  304.     |
  305.     |    > (setq table-saw (send my-tools :new 'AC nil 'cuts))
  306.     |    #<Object: #2db00>
  307.     |________________________________________________________________
  308.  
  309.  
  310. So, a class of objects called MY-TOOLS was created.  Note that the class
  311. object  MY-TOOLS was created by sending the :NEW message to the built-in
  312. CLASS  object.  Within  the  MY-TOOL  class,  there are three  instances
  313. called DRILL, HAND-SAW and TABLE-SAW.  These were created by sending the
  314. :NEW message to the MY-TOOLS  class object.  Notice that the  parameters
  315. followed the message selector.
  316.  
  317.  
  318. INSTANCES
  319.  
  320. The  following  is a display of the  contents of some of the  previously
  321. created instances:
  322.  
  323.      ________________________________________________________________
  324.     |
  325.     |    > (send drill :show)
  326.     |    Object is #<Object: #2ddbc>, Class is #<Object: #277a6>
  327.     |      POWER = AC
  328.     |      MOVEABLE = T
  329.     |      OPERATION = HOLES
  330.     |    #<Object: #2ddbc>
  331.     |
  332.     |    > (send hand-saw :show)
  333.     |    Object is #<Object: #2dc40>, Class is #<Object: #277a6>
  334.     |      POWER = NONE
  335.     |      MOVEABLE = T
  336.     |      OPERATION = CUTS
  337.     |    #<Object: #2dc40>
  338.     |________________________________________________________________
  339.  
  340.  
  341. From  the  display  of  these  instances  you  can see  there  are  some
  342. components and values.  The components of an instance are:
  343.  
  344.     Class Pointer           This  pointer  shows to which  class the
  345.                 current object instance  belongs.  It is
  346.                 through this link that the system  finds
  347.                 the methods to execute for the  received
  348.                 messages.
  349.  
  350.     Instance Variables      The Instance  Variables (IVAR) component
  351.     and Values        lists what  variables  exist  within the
  352.                 instance.  The Instance Values component
  353.                 holds  what the  current  values  of the
  354.                 variables  are.  Instance  Variables are
  355.                 used to hold state  information for each
  356.                 instance.  There  will  be  a  group  of
  357.                 Instance Variables for each instance.
  358.  
  359.  
  360.  
  361.  
  362. METHODS
  363.  
  364. There have been a few of the messages and methods in XLISP shown to this
  365. point (:NEW and :SHOW).  The following are the methods built into XLISP:
  366.  
  367.     :ANSWER         The  :ANSWER  method  allows  you to  define  or
  368.             change methods within a class.
  369.  
  370.     :CLASS         The :CLASS method returns the class of an object.
  371.  
  372.     :ISNEW          The :ISNEW method  causes an instance to run its
  373.             initialization  code.  When the :ISNEW method is
  374.             run on a class, it resets the class state.  This
  375.             allows  you  to  re-define  instance  variables,
  376.             class variables, etc.
  377.  
  378.     :NEW            The :NEW method allows you to create an instance
  379.             when the :NEW message is sent to a  user-defined
  380.             class.  The :NEW  method  allows you to create a
  381.             new class (when the :NEW  message is sent to the
  382.             built-in CLASS).
  383.  
  384.     :SHOW         The :SHOW method displays the instance or class.
  385.  
  386.  
  387.  
  388. SENDING MESSAGES TO A SUPERCLASS
  389.  
  390. In  addition  to the SEND  function,  there is another  function  called
  391. SEND-SUPER.  The SEND-SUPER  function causes the specified message to be
  392. performed  by the  superclass  method.  This  is a  mechanism  to  allow
  393. chaining of methods in a class hierarchy.  This chaining behavior can be
  394. achieved  by  creating a method  for a class with the  :ANSWER  message.
  395. Within the body of the  method,  you  include a  SEND-SUPER  form.  This
  396. function is allowed only inside the  execution of a method of an object.
  397.  
  398.  
  399. OBJECT AND CLASS
  400.  
  401. The definition of the built-in class OBJECT is:
  402.  
  403.      ________________________________________________________________
  404.     |
  405.     |    > (send object :show)
  406.     |    Object is #<Object: #23fd8>, Class is #<Object: #23fe2>
  407.     |      MESSAGES = ((:SHOW . #<Subr-: #23db2>) 
  408.     |                (:CLASS . #<Subr-: #23dee>) 
  409.     |              (:ISNEW . #<Subr-: #23e2a>))
  410.     |      IVARS = NIL
  411.     |      CVARS = NIL
  412.     |      CVALS = NIL
  413.     |      SUPERCLASS = NIL
  414.     |      IVARCNT = 0
  415.     |      IVARTOTAL = 0
  416.     |    #<Object: #23fd8>
  417.     |________________________________________________________________
  418.  
  419.  
  420. Note that OBJECT is a class - as opposed to an "instance-style"  object.
  421. OBJECT has no superclass, it is the top or root of the class  hierarchy.
  422. OBJECT's class is CLASS.
  423.  
  424.      ________________________________________________________________
  425.     |
  426.     |    > (send class :show)
  427.     |    Object is #<Object: #23fe2>, Class is #<Object: #23fe2>
  428.     |      MESSAGES = ((:ANSWER . #<Subr-: #23e48>) 
  429.     |                (:ISNEW . #<Subr-: #23e84>) 
  430.     |              (:NEW . #<Subr-: #23ea2>))
  431.     |      IVARS = (MESSAGES IVARS CVARS CVALS SUPERCLASS 
  432.     |           IVARCNT IVARTOTAL)
  433.     |      CVARS = NIL
  434.     |      CVALS = NIL
  435.     |      SUPERCLASS = #<Object: #23fd8>
  436.     |      IVARCNT = 7
  437.     |      IVARTOTAL = 7
  438.     |    #<Object: #23fe2>
  439.     |________________________________________________________________
  440.  
  441.  
  442. CLASS has a superclass of OBJECT.  It's class is itself - CLASS. 
  443.  
  444.  
  445. Path: hplabsz!hplabs!hpfcso!hpfcbig!tim
  446. From: tim@hpfcbig.SDE.HP.COM (Tim Mikkelsen)
  447. Newsgroups: comp.lang.lisp.x
  448. Subject: Re: intro to XLISP objects
  449. Message-ID: <1170006@hpfcbig.SDE.HP.COM>
  450. Date: 12 Feb 90 16:24:20 GMT
  451. References: <1170004@hpfcbig.SDE.HP.COM>
  452. Organization: HP SESD, Fort Collins, CO
  453. Lines: 228
  454.  
  455.  
  456. A MORE REALISTIC EXAMPLE 
  457. ______________________________________________________________________________
  458.  
  459.  
  460. The following is an example, using the idea of tools again.  It contains
  461. a hierarchy of tool  classes.  The top of the class  hierarchy is TOOLS.
  462. HAND-TOOLS and SHOP-TOOLS are sub-classes of TOOLS.  The example creates
  463. instances of these  sub-classes.  It is possible to extend this  example
  464. in various ways.  One obvious  extension would be to create a third tier
  465. of classes  under  HAND-TOOLS  that could  contain  classes like drills,
  466. screwdrivers, pliers and so on.
  467.  
  468.  
  469.  
  470.  
  471. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  472. ;
  473. ;    File name:    tools.lsp
  474. ;    Author:        Tim Mikkelsen
  475. ;    Description:    Object-oriented example program
  476. ;    Language:    XLISP 2.0
  477. ;
  478. ;    Date Created:    10-Jan-1988
  479. ;    Date Updated:    2-Apr-1989
  480. ;    
  481. ;    (c) Copyright 1988, by Tim Mikkelsen, all rights reserved.
  482. ;        Permission is granted for unrestricted non-commercial use.
  483. ;
  484. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  485.  
  486. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  487. ;
  488. ;    Define the superclasses and classes
  489. ;
  490. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  491.  
  492. ;
  493. ; make TOOLS superclass
  494. ;    with a different :ISNEW method
  495. ;    added methods are :BORROW and :RETURN
  496. ;    class variables are    NUMBER        contains # of tool instances
  497. ;                ACTIVE-LIST    contains list of current objects
  498. ;    instance variables are     POWER         list - (AC BATTERY HAND)
  499. ;                MOVEABLE     CAN-CARRY or CAN-ROLL or FIXED
  500. ;                OPERATIONS    list
  501. ;                MATERIAL     list - (WOOD METAL PLASTIC ...)
  502. ;                PIECES         list
  503. ;                LOCATION    HOME or person's name
  504. ;
  505.  
  506. (setq tools (send class :new '(power 
  507.                    moveable 
  508.                    operations 
  509.                    material 
  510.                    pieces 
  511.                    location) 
  512.                  '(number active-list)))
  513. (send tools :answer :isnew '() 
  514.                    '((if (null number) (setq number 1)
  515.                                  (setq number (1+ number)))
  516.                  (setq active-list (cons self active-list))
  517.                  (setq location 'home)))
  518. (send tools :answer :borrow '(by-who)
  519.                     '((if (eq location 'home) (setq location by-who)
  520.                                      (print "you can't"))))
  521. (send tools :answer :return '()
  522.                     '((if (eq location 'home) (print "got it already")
  523.                                      (setq location 'home))))
  524.  
  525. ;
  526. ; make HAND-TOOLS class
  527. ;    with a different :ISNEW method
  528. ;    new instance variable    WEIGHT        <number> of pounds
  529. ;    the rest is inherited from TOOLS 
  530.  
  531. (setq hand-tools (send class :new '(weight) '() tools))
  532. (send hand-tools :answer :isnew '(pow op mat parts w-in)
  533.                     '((setq power pow)
  534.                       (setq moveable 'can-carry)
  535.                       (setq operations op)
  536.                       (setq material mat)
  537.                           (setq pieces parts)
  538.                       (setq weight w-in)
  539.                       (send-super :isnew)))
  540.  
  541. ;
  542. ; make SHOP-TOOLS class
  543. ;    with a different :ISNEW method
  544. ;    no new instance variables
  545. ;    the rest is inherited from TOOLS 
  546.  
  547. (setq shop-tools (send class :new '() '() tools))
  548. (send shop-tools :answer :isnew '(pow mov op mat parts)
  549.                     '((setq power pow)
  550.                      (setq moveable mov)
  551.                      (setq operations op)
  552.                      (setq material mat)
  553.                      (setq pieces parts)
  554.                      (send-super :isnew)))
  555.  
  556. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  557. ;
  558. ;    Create instances of various tool classes 
  559. ;
  560. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  561.  
  562. (setq hand-drill (send hand-tools :new         ; make an instance - HAND-DRILL
  563.                  '(ac) 
  564.                  '(drill polish grind screw)
  565.                  '(wood metal plastic)
  566.                  '(drill drill-bits screw-bits buffer)
  567.                  '2.5))
  568.  
  569. (setq table-saw (send shop-tools :new         ; make an instance - TABLE-SAW
  570.                  '(ac)
  571.                  'fixed
  572.                  '(rip cross-cut)
  573.                  '(wood plastic)
  574.                  '(saw blades fence)))
  575.  
  576.  
  577. (setq radial-arm (send shop-tools :new         ; make an instance = RADIAL-ARM
  578.                  '(ac)
  579.                  'can-roll
  580.                  '(rip cross-cut)
  581.                  '(wood plastic)
  582.                  '(saw blades dust-bag)))
  583.  
  584.  
  585. The following  session shows how to use the tool  definitions  from this
  586. better  example.  The example starts at the OS shell and brings up xlisp
  587. running the file 'tools.lsp'.
  588.  
  589.      ________________________________________________________________
  590.     |
  591.     |    cmd? xlisp tools
  592.     |    ; loading "init.lsp"
  593.     |    ; loading "tools.lsp"
  594.     |    > (send hand-drill :borrow 'fred)
  595.     |    FRED
  596.     |
  597.     |    > (send table-saw :return)
  598.     |    "got it already"
  599.     |    "got it already"
  600.     |
  601.     |    > (send hand-drill :borrow 'joe)
  602.     |    "you can't"
  603.     |    "you can't"
  604.     |
  605.     |    > (send hand-drill :return)
  606.     |    HOME
  607.     |________________________________________________________________
  608.  
  609.  
  610. So, Fred was able to borrow the HAND-DRILL.  When an attempt was made to
  611. return the  TABLE-SAW,  it was  already  at home.  A second  attempt  to
  612. borrow the HAND-DRILL  indicated that "you can't" because it was already
  613. lent out.  Lastly, the HAND-DRILL was returned successfully.  (Note that
  614. the "got it  already"  and "you  can't"  strings  show up  twice  in the
  615. display because the methods both print and return the string.)
  616.  
  617. The following session shows the structure of the TOOLS object:
  618.  
  619.      ________________________________________________________________
  620.     |
  621.     |    > (send tools :show)
  622.     |    Object is #<Object: #276fc>, Class is #<Object: #23fe2>
  623.     |      MESSAGES = ((:RETURN . #<Closure-:RETURN: #2dbd0>) 
  624.     |                (:BORROW . #<Closure-:BORROW: #2ddba>) 
  625.     |              (:ISNEW . #<Closure-:ISNEW: #274a4>))
  626.     |      IVARS = (POWER MOVEABLE OPERATIONS MATERIAL PIECES LOCATION)
  627.     |      CVARS = (NUMBER ACTIVE-LIST)
  628.     |      CVALS = #(3 (#<Object: #2cadc> 
  629.     |                 #<Object: #2cda2> 
  630.     |           #<Object: #2d0e0>))
  631.     |      SUPERCLASS = #<Object: #23fd8>
  632.     |      IVARCNT = 6
  633.     |      IVARTOTAL = 6
  634.     |    #<Object: #276fc>
  635.     |________________________________________________________________
  636.  
  637.  
  638. The two TOOLS sub-classes HAND-TOOLS and SHOP-TOOLS structure looks like:
  639.  
  640.      ________________________________________________________________
  641.     |
  642.     |    > (send hand-tools :show)
  643.     |    Object is #<Object: #2dab8>, Class is #<Object: #23fe2>
  644.     |      MESSAGES = ((:ISNEW . #<Closure-:ISNEW: #2d7a2>))
  645.     |      IVARS = (WEIGHT)
  646.     |      CVARS = NIL
  647.     |      CVALS = NIL
  648.     |      SUPERCLASS = #<Object: #276fc>
  649.     |      IVARCNT = 1
  650.     |      IVARTOTAL = 7
  651.     |    #<Object: #2dab8>
  652.     |
  653.     |    > (send shop-tools :show)
  654.     |    Object is #<Object: #2d680>, Class is #<Object: #23fe2>
  655.     |      MESSAGES = ((:ISNEW . #<Closure-:ISNEW: #2d450>))
  656.     |      IVARS = NIL
  657.     |      CVARS = NIL
  658.     |      CVALS = NIL
  659.     |      SUPERCLASS = #<Object: #276fc>
  660.     |      IVARCNT = 0
  661.     |      IVARTOTAL = 6
  662.     |    #<Object: #2d680>
  663.     |________________________________________________________________
  664.  
  665.  
  666. The class HAND-TOOLS has an instance HAND-DRILL which looks like:
  667.  
  668.      ________________________________________________________________
  669.     |
  670.     |    > (send hand-drill :show)
  671.     |    Object is #<Object: #2d0e0>, Class is #<Object: #2dab8>
  672.     |      WEIGHT = 2.5
  673.     |      POWER = (AC)
  674.     |      MOVEABLE = CAN-CARRY
  675.     |      OPERATIONS = (DRILL POLISH GRIND SCREW)
  676.     |      MATERIAL = (WOOD METAL PLASTIC)
  677.     |      PIECES = (DRILL DRILL-BITS SCREW-BITS BUFFER)
  678.     |      LOCATION = HOME
  679.     |    #<Object: #2d0e0>
  680.     |________________________________________________________________
  681.