v10i088: XLisP 2.1 sources 1a (1/3) / 5
Gary Murphy
garym at cognos.UUCP
Tue Feb 27 14:10:12 AEST 1990
Posting-number: Volume 10, Issue 88
Submitted-by: garym at cognos.UUCP (Gary Murphy)
Archive-name: xlisp21/part01
Another attempt to get these sources to you: my first batch ran into 100k
message limits, which means the message counts on any files you've received
so far are not quite correct.
The whole kit should consist of 1a 1b 1c 2 3a 3b 4a 4b and 5 - I promise I'll
be better at this next time :-)
[Ugh. ++bsa]
I have included the sources as I downloaded them from MIPS BBS, with the
collected bug-fixes/extensions &c appended as a collection of news
articles. This also includes the WINTERP and XLISP examples and tutorials
recendly posted to comp.lang.lisp.x
------------------------------------------------------------------------
#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# betz
# readme.1st
# readme.src
# winterp.doc
# xlisp.eg
# xlisp.ref
# xlisp.txt
# This archive created: Sun Feb 18 23:27:40 1990
# By: Gary Murphy ()
export PATH; PATH=/bin:$PATH
echo shar: extracting "'betz'" '(1164 characters)'
if test -f 'betz'
then
echo shar: over-writing existing file "'betz'"
fi
sed 's/^X//' << \SHAR_EOF > 'betz'
XFrom sce!mitel!uunet!samsung!brutus.cs.uiuc.edu!psuvax1!rutgers!cmcl2!dasys1!intern Fri Nov 24 09:01:48 EST 1989
XArticle: 33 of comp.lang.lisp.x
XPath: cognos!sce!mitel!uunet!samsung!brutus.cs.uiuc.edu!psuvax1!rutgers!cmcl2!dasys1!intern
XFrom: intern at dasys1.UUCP (Steve Faiwiszewski)
XNewsgroups: comp.lang.lisp.x
XSubject: Re: Author! Author!
XMessage-ID: <11273 at dasys1.UUCP>
XDate: 22 Nov 89 02:55:16 GMT
XReferences: <1989Nov9.180124.24190 at rpi.edu>
XReply-To: intern at dasys1.UUCP (Steve Faiwiszewski)
XOrganization: The Big Electric Cat
XLines: 15
X
XIn article <1989Nov9.180124.24190 at rpi.edu> jefu at pawl.rpi.edu (Jeffrey Putnam) writes:
X>Does anyone have any suggestions for an email path to David Betz?
X>(I know this has been asked before, but news has this habit of expiring
X>things...)
X>
X
XDavid Betz' CompuServe id is 76704,47. Last time I corresponded with him
Xon CIS was about 6 months ago. You can mail to him from the net by sending
Xto 76704.47 at compuserve.com
X
X - Steve -
X--
X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XSteve Faiwiszewski bang : {sun!hoptoad , cmcl2!hombre} !dasys1!intern
X domain : intern at dasys1.UUCP
X
X
SHAR_EOF
if test 1164 -ne "`wc -c 'betz'`"
then
echo shar: error transmitting "'betz'" '(should have been 1164 characters)'
fi
echo shar: extracting "'readme.1st'" '(6702 characters)'
if test -f 'readme.1st'
then
echo shar: over-writing existing file "'readme.1st'"
fi
sed 's/^X//' << \SHAR_EOF > 'readme.1st'
XThis is a list of new features in XLISP version 2.0 as of 15Nov87:
X
XSymbols have two value cells, one for normal values and one for
Xfunction values. SETQ sets the normal value, DEFUN sets the
Xfunctional value.
X
XThe most important change from version 1.7 to 2.0 of XLISP is that
Xit is now possible to save XLISP's workspace between sessions. This
Xfeature isn't necessarily part of every implementation of XLISP 2.0
Xsince it is controlled by a compile-time conditional. Check the file
X'xlisp.h' to see if the symbol SAVERESTORE is defined for your machine
Xbefore you try to use these functions.
X
XThe &key lambda list keyword is now supported as are initialization forms
Xfor &optional, &key and &aux parameters. The supplied-p variables are
Xalso supported for &optional and &key parameters.
X
XNew functions and special forms:
X
X(save filename) ; *** NOT IN ALL 2.0 IMPLEMENTATIONS ***
X(restore filename) ; *** NOT IN ALL 2.0 IMPLEMENTATIONS ***
X(subseq string start [end])
X(open name &key :direction)
X(vector [expr]...)
X(block name [expr]...)
X(return-from name [value])
X(tagbody [tag|expr]...)
X(psetq [sym value]...)
X(flet ([sym lambda-list [body]...]...) [expr]...)
X(labels ([sym lambda-list [body]...]...) [expr]...)
X(macrolet ([sym lambda-list [body]...]...) [expr]...)
X(unwind-protect expr [expr]...)
X(when test [expr]...)
X(unless test [expr]...)
X(loop [expr]...)
X(progv symbols values [expr]...)
X(pprint expr [stream])
X(string< str1 str2 &key :start1 :end1 :start2 :end2)
X(string= str1 str2 &key :start1 :end1 :start2 :end2)
X(string> str1 str2 &key :start1 :end1 :start2 :end2)
X(string<= str1 str2 &key :start1 :end1 :start2 :end2)
X(string/= str1 str2 &key :start1 :end1 :start2 :end2)
X(string>= str1 str2 &key :start1 :end1 :start2 :end2)
X(string-lessp str1 str2 &key :start1 :end1 :start2 :end2)
X(string-equal str1 str2 &key :start1 :end1 :start2 :end2)
X(string-greaterp str1 str2 &key :start1 :end1 :start2 :end2)
X(string-not-greaterp str1 str2 &key :start1 :end1 :start2 :end2)
X(string-not-equal str1 str2 &key :start1 :end1 :start2 :end2)
X(string-not-lessp str1 str2 &key :start1 :end1 :start2 :end2)
X(string-trim bag string)
X(string-left-trim bag string)
X(string-right-trim bag string)
X(string-upcase string &key :start :end)
X(string-downcase string &key :start :end)
X(nstring-upcase string &key :start :end)
X(nstring-downcase string &key :start :end)
X(symbol-function sym)
X(send obj msg [expr]...)
X(send-super msg [expr]...)
X(integerp expr)
X(floatp expr)
X(stringp expr)
X(arrayp expr)
X(streamp expr)
X(objectp expr)
X(fboundp expr)
X(characterp expr)
X(int-char expr)
X(char-int expr)
X(read-byte [stream])
X(write-byte expr [stream])
X(make-string-input-stream string [start [end]])
X(make-string-output-stream)
X(get-output-stream-string stream)
X(get-output-stream-list stream)
X(get-lambda-expression closure)
X(gcd expr1 expr2)
X(macroexpand form)
X(macroexpand-1 form)
X
XThere is now a real character data type. All functions that are
Xsupposed to return characters (like READ-CHAR) now do.
X
XThe reader is now capable of handling both single and multiple escapes.
XThis means that it is possible to read the symbol |aBc| and get a symbol
Xwith the print name "aBc". The backslash can also be used as a single
Xescape. The same symbol could have been written \aB\c.
X
XThe read table now supports the character types :SESCAPE for single
Xescape and :MESCAPE for multiple escapes.
X
XThe reader also supports the reader macros:
X
X #:symbol an uninterned symbol
X #| ... |# a comment
X #Onumber an octal number
X #Bnumber a binary number
X
XThe following symbols preserve a history of values used by the
Xread-eval-print loop:
X
X - the current input expression
X + the last expression read
X ++ the previous value of +
X +++ the previous value of ++
X * the result of the last evaluation
X ** the previous value of *
X *** the previous value of **
X
XThe global symbol *PRINT-CASE* was added to control the output case of
Xsymbols. Its default value is :UPCASE which will cause symbols to
Xbe printed in uppercase. You can change it to :DOWNCASE to get symbols
Xto print in lowercase.
X
XI have added the functions FIRST, SECOND, THIRD, FOURTH and REST as
Xsynonyms for CAR, CADR, CADDR, CADDDR and CDR.
X
XChanged the default value of *print-case* to :upcase.
X
XAdded macros to init.lsp for:
X
X (defvar sym &optional val)
X (defparameter sym val)
X (defconstant sym val)
X
XThese symbols control the format in which numbers are printed. They
Xshould be set to printf format strings.
X
X *integer-format* (default is "%d" or "%ld")
X *float-format* (default is "%g")
X
X(substr string start [length]) is replaced by:
X (subseq string start [end])
X
X(openi name) is replaced by: (open name :direction :input)
X(openo name) is replaced by: (open name :direction :output)
X
XOPEN, LOAD, SAVE and RESTORE take strings or symbols as file names.
XIf a symbol is given, the print name of the symbol is used as the base
Xfilename and the default extension (if any) is appended.
X
XRenamed MEM to ROOM and TRANSCRIPT to DRIBBLE.
X
XAdded a trace facility. The evaluator will now print trace
Xinformation for function and macro calls. The names of the
Xfunctions and macros to trace should be in a list that is stored
Xas the value of *TRACELIST*.
X
XAdded macro definitions for TRACE and UNTRACE to "init.lsp".
XTrace output goes to the stream that is the value of *TRACE-OUTPUT*.
X
XRemoved the hard wired prompting from READ. There is no longer
Xan unmatched left paren counter, but the debug level prompt remains.
X
XThe symbols *ERROR-OUTPUT* and *DEBUG-IO* have been added and
Xare bound to streams that are used for error output and debug
Xi/o respectively.
X
XThe symbol *GC-HOOK* has been added. If it is bound to a function
Xof two arguments, that function will be called after the garbage
Xcollector runs. The two parameters are the total number of nodes
Xand the number free after the garbage collection.
X
XAdded the function (COMMAND-POINT-SIZE <n>) to the Macintosh version
Xto set the point size for the text in the command window. The default
Xpoint size is 9.
X
XThe SEND-SUPER function replaces the :SENDSUPER message to objects.
XAll messages must be sent using either the SEND function or the
XSEND-SUPER function. In other words, the syntax:
X
X (Class :new '(a b c))
X
Xmust now be written as:
X
X (send Class :new '(a b c))
X
Xand
X
X (self :sendsuper :msg 1 2 3)
X
Xmust now be written as:
X
X (send-super :msg 1 2 3)
X
XThis is because the CAR of a form is no longer evaluated. To get the
Xeffect of having the function position evaluated, use the FUNCALL form.
X
XThe syntax of LOAD has changed from:
X
X (load name [verbose-flag [print-flag]])
X
Xto:
X
X (load name &key :verbose :print)
X
X
X
SHAR_EOF
if test 6702 -ne "`wc -c 'readme.1st'`"
then
echo shar: error transmitting "'readme.1st'" '(should have been 6702 characters)'
fi
echo shar: extracting "'readme.src'" '(466 characters)'
if test -f 'readme.src'
then
echo shar: over-writing existing file "'readme.src'"
fi
sed 's/^X//' << \SHAR_EOF > 'readme.src'
XThis archive contains the IBM-PC specific source code for XLISP
Xversion 2.1. In order to recompile XLISP, you'll also need the
Xgeneric code archive. These files were designed to be used with
XTurbo C v2.0 and will probably need to be changed to use any other
Xcompiler. Before attempting to recompile any of the modules, make
Xsure that the symbol _TURBOC_ is defined at the top of 'xlisp.h'
Xwhere the machine type is specified (right under the copyright
Xnotice).
X
X
SHAR_EOF
if test 466 -ne "`wc -c 'readme.src'`"
then
echo shar: error transmitting "'readme.src'" '(should have been 466 characters)'
fi
echo shar: extracting "'winterp.doc'" '(14611 characters)'
if test -f 'winterp.doc'
then
echo shar: over-writing existing file "'winterp.doc'"
fi
sed 's/^X//' << \SHAR_EOF > 'winterp.doc'
XFrom sce!mitel!uunet!tut.cis.ohio-state.edu!ucbvax!hplabs!hplabsz!mayer Thu Jan 11 12:51:21 EST 1990
XArticle: 2234 of comp.lang.lisp
XPath: cognos!sce!mitel!uunet!tut.cis.ohio-state.edu!ucbvax!hplabs!hplabsz!mayer
XFrom: mayer at hplabsz.HPL.HP.COM (Niels Mayer)
XNewsgroups: comp.lang.lisp
XSubject: Re: XLISP Object Method Selectors :new and :isnew.
XMessage-ID: <4613 at hplabsz.HPL.HP.COM>
XDate: 10 Jan 90 07:26:26 GMT
XReferences: <1511 at dinl.mmc.UUCP>
XReply-To: mayer at hplabs.hp.com (Niels Mayer)
XOrganization: Hewlett-Packard Labs, Software Technology Lab, Palo Alto, CA.
XLines: 308
XSummary:
XExpires:
XSender:
XFollowup-To:
X
XIn article <1511 at dinl.mmc.UUCP> noren at dinl.UUCP (Charles Noren) writes:
X>It's been a while since I've been on the net. I can no longer
X>access comp.lang.lisp.x from our site, I suppose it went away?
X
Xit's still there...
X
X>I've just starting playing with XLISP v2.0, particularly the
X>object-oriented features of it. I've created new classes with
X>instance and class variables, and I've used the :new selector
X>to do so and it works just fine. However, I see the :isnew
X>selector in the documentation and I was wondering how that works
X>compared to :new.
X
XWhen I first looked at XLISP, I too found the documentation on the
Xobject system to be a little terse. Everything becomes much clearer
Xonce you see some examples.
X
XI recently wrote up some documentation on XLISP's object system for
Xuse with WINTERP (an XLISP-based rapid prototyping environment for
Xapplications based on the OSF Motif widgets). The following excerpt
Xfrom winterp/doc/winterp.doc may help (get winterp via anonymous ftp
Xfrom expo.lcs.mit.edu:oldcontrib/winterp.tar.Z). In particular, your
Xquestion about :ISNEW is answered in the "object initialization"
Xsection.
X
X --------------------
X
X* Introduction to XLISP objects and Widgets.
X
XWINTERP uses XLISP's object system as its interface to the class hierarchy
Xof widgets provided by Motif. Specifically, each Motif widget class is
Xrepresented by one or more object classes in WINTERP. In order to best
Xunderstand the capabilities of WINTERP's Motif interface, a brief review of
Xthe XLISP object system is in order. You may also want to consult the XLISP
Xdocumentation ./winterp/doc/xLisp.doc for a more precise definition of the
Xobject system.
X
XXLISP Classes describe the type of a particular object by declaring a set
Xof variables held in each object. These "instance variables" may only be
Xaccessed by "methods" that respond to "messages" sent to the object.
XMethods are defined for particular classes, and functionality of other
Xclasses may be incorporated into new classes via "inheritance". From
XXLISP, Motif widget classes look just like normal XLISP objects -- that
Xmeans that you can easily extend the functionality of Motif widgets by
Xadding your own methods to a particular widget class. You may also use
Xinheritance to attach your own data structures to widgets. The result is
Xthat WINTERP provides a very clean way to interactively rapid-prototype an
Xapplication, while also providing mechanisms for code structuring and reuse.
XThe latter is necessary in evolving from prototype to a structured,
Xmaintainable, and customizable deliverable.
X
X
X** Creating new objects.
X
XCreate a new instance of a class by sending the message :NEW to
X<a_class_instance>:
X
X (SEND <a_class_instance> :NEW <parameters>)
X
X<a_class_instance> is in fact an instance of class CLASS. Class CLASS allows
Xyou to define new class instances by specifying the instance variables and
Xparent class of a particular class.
X
X
X** Declaring a class.
X
XTo declare a "base class" object, that is, an object with no parent object,
Xjust send message :NEW to the object <CLASS>
X
X (SEND CLASS :NEW '(<ivar0> ... <ivarN>)
X ['(<cvar0> ... <cvarM>)])
X
X'(<ivar0> ... (ivarN>) are a list of symbols. Each <ivar-i> names an
Xinstance variable of the class. '(<cvar0> ... <cvarM>)]) are an optional
Xlist of variables that are shared among all instances of that particular
Xclass.
X
X
X** Defining methods.
X
XWhen a "message" is sent to an object, XLISP searches for a "method" to
Xanswer the message. A method is a piece of Lisp code that is executed when
Xa particular message is sent to an object. Within the code of a method, all
Xobject instance and class variables are accessible. Furthermore, the symbol
X'self' is bound to the object the message was sent to.
X
XMethods are defined by sending the message :ANSWER to <a_class_instance>:
X
X (SEND a_class_instance :ANSWER <:msg> <parameters> <code>)
X
Xwhere <:msg> is a keyword symbol (a symbol with a ':' prefix) representing
Xthe message; <parameters> are the arguments given along with the message.
XSee the documentation on "lambda lists" in /winterp/doc/xLisp.doc p.12 for
Xdetails. <code> is a list of s-expressions which get evaluated in response
Xto a message. The lexical environment that existed for the call to :ANSWER
Xwill be used for value and functional bindings during method evaluation.
X
XIf you need to remember what the syntax is, consider the memory-helper
X "this class :ANSWERs to :MESSAGE..." == (send <cls> :ANSWER :MESSAGE ...)
X
X
X** Inheritance
X
XSo far, the object system we just described supports *encapsulation*.
XEncapsulation is good programming practice because it helps localize and
Xdetangle complexity. Unfortunately, encapsulation runs counter to
Xflexibility because making flexible use of an object may require that
Xcertain groups of instance variables be accessed by different layers of new
Xfunctionality. Most often, one wants to *reuse* aspects of a particular
Xclass in creating code that specializes and alters the functionality of
Xthat class. A compromise between encapsulation and flexibility is found by
Xusing *inheritance* in an object system. Inheritance is used to allow a
X *subclass* to specialize the functionality of it's *parent class* (aka,
Xthe *superclass*):
X
X (send Class :NEW '(<ivar0> ... <ivarN>)
X '(<cvar0> ... <cvarM>)
X <superclass>)
X
X(<ivar0> ... <ivarN>) is a list of new instance variables in the subclass;
X(<cvar0> ... <cvarN>) is a list of new class variables in the subclass;
X<superclass> is a class instance representing the parent from which
Xthe new subclass inherits variables and methods.
X
X"Inheritance" is occurring because all the instance variables of all the
Xparent classes of the new subclass become the variables of each subclass
Xinstance. Furthermore, all methods defined on a parent class may also be
Xused on a subclass instance. Note that while a subclass' methods can access
Xthe variables defined on the parent classes, the reverse isn't true.
X
X
X** Object initialization.
X
XAs mentioned earlier, new object instances are created by sending the
Xmessage :NEW to a class object. Sending the message :NEW to a class
Xautomatically sends message :ISNEW to the newly created instance. By
Xdefault :ISNEW on an instance is a no-op method defined on class 'Object',
Xwhich is the implicit [(grand)*]parent of all instances. If you want to
Xinitialize the instance/class variables of a particular class, you must
Xdefine an :ISNEW method on the class. Any parameters originally sent to
Xthe :NEW method will be passed on to the :ISNEW method and may be used to
Xinitialize an object to outside-world parameters.
X
X
X** Example of using OOP features of XLISP with Motif widgets:
X
XAs currently implemented, the Motif class xmListWidgetClass makes it a bit
Xbaroque to create browsers (hopefully this will change in Motif 1.1). The
Xproblem is that a "browser" is a kind of application that lends itself to
Xobject oriented techniques that are not always straightforward to support
Xin C. One often has a collection of 'things' that one wants to display in a
X'list' and perform actions on the 'thing' corresponding to the visual
Xselection of an element in the displayed list. xmListWidgetClass will
Xdisplay an arrray of XmStrings in a list. When one or more elements in the
Xlist are selected, XmStrings corresponding to the selected elements are
Xreturned. Since the XmStrings you put into the list widget are not the
XXmStrings you get out, you must call XmStringCompare on each element of the
Xcollection of 'things' to find out which ones are selected. Presumably,
Xyou'll want to do more than just get back an XmString... normally one will
Xwant to access data structures associated with the XmString so as to perform
Xan action dependent on those structures. This could be done with a lookup
Xtable, but there's also a better way...
X
XWINTERP allows us to subclass the Motif list widget so as to make it have
Xthe kind of functionality we want. This subclass will contain an additional
Xinstance variable 'items' which is an array of arbitrary XLISP objects to
Xbe displayed in a textual browser made from the list widget. These objects
Xcan have completely different internal representations -- the only
Xrequirement is that they follow the protocol of being able to respond to
Xthe messages :DISPLAY_STRING and :DEFAULT_ACTION. :DISPLAY_STRING returns a
Xstring representation of the object to be displayed in the browser.
X:DEFAULT_ACTION is the action to be performed when a list item is browsed
X(by double clicking on the item).
X
XThe following creates the subclass <List_Browser> from superclass
X<XM_LIST_WIDGET_CLASS>:
X
X (setq List_Browser
X (send Class :NEW ;create a class inst
X '(items) ;new instance vars
X '() ;no class vars
X XM_LIST_WIDGET_CLASS)) ;superclass
X
XSo now all instances of <List_Browser> will contain an instance variable
X<items> and will respond to all the messages understood by the
XXM_LIST_WIDGET_CLASS. We want our list browser to behave as described
Xabove, so we define an :ISNEW method to initialize instance variable
X<items> to the list of arbitrary objects to be displayed. <items> gets
Xinitialized to an array of objects, the list widget is created, and a
XXmNdefaultActionCallback is setup so that a double click will send the
Xmessage :DEFAULT_ACTION to the browsed item:
X
X ;; (send List_Browser :new <items_list> <args-for-the-list-widget>)
X ;; <items_list> is a list of BROWSER_OBJECTs as described above.
X ;; <args-for-the-list-widget> -- these are the arguments that
X ;; will be passed on to the list widget
X ;;
X (send List_Browser :answer :isnew '(items_list &rest args)
X '(
X (let* (
X (items_end_idx (length items_list))
X (display_items (make-array items_end_idx)))
X
X ;; initialize the 'items' instance variable so that it
X ;; holds all the BROWSER_OBJECTs passed in <items_list>
X (setq items (make-array items_end_idx)) ;create the array
X (do ( ;copy elts from list to array
X (i 0 (1+ i))
X (elts items_list (cdr elts)))
X ;; loop till no more elts
X ((null elts))
X ;; loop body
X (setf (aref items i) (car elts))
X (setf (aref display_items i)
X (send (car elts) :display_string))
X )
X
X ;; initialize the widget, passing in the browser items.
X (apply 'send-super `(:isnew
X , at args
X :xmn_selection_policy :browse_select
X :xmn_items ,display_items
X :xmn_item_count ,items_end_idx
X ))
X )
X
X ;; set up a callback on the list widget initialized above such
X ;; that a double click on the browser-item will send the
X ;; message :default_action to the BROWSER_OBJECT.
X (send-super :add_callback :xmn_default_action_callback
X '(callback_item_position)
X '((send (aref items (1- callback_item_position))
X :default_action))
X )
X )
X )
X
X
XIn the above code, SEND-SUPER works just like send, except that it doesn't
Xrequire you to give it the object to send the message to. Instead, it
Ximplicitly assumes that it will be called from within a method, and will
Xautomatically send the message to a superclass of the object's class. The
X(apply 'send-super ...) form is actually calling the :ISNEW (instance
Xinitializer) method on XM_LIST_WIDGET_CLASS, which actually creates the
Xwidget via XmCreateList() or XmCreateScrolledList(). The APPLY '`'
X(BACKQUOTE) and '&rest args' (LAMBDA LIST) features of Lisp allow us to
Xsplice in the argument list passed to the instance of List_Browser into the
Xfunction that actually creates the widget. Finally, method :add_callback is
Xthe WINTERP equivalent of XtAddCallback(). See the documentation on methods
Xon WIDGET_CLASS for more details.
X
XThe Motif List widget also defines a number of "methods" implemented as C
Xroutines such as XmListAddItem(), XmListAddItemUnselected(),
XXmListDeleteItem(), and XmListDeletePos(). In WINTERP, we define these as
Xmethods :ADD_ITEM, :ADD_ITEM_UNSELECTED, :DELETE_ITEM, and :DELETE_POS
Xrespectively. Since these methods modify the collection of objects
Xrepresented by the list widget, we must update the internal array of
Xobjects <items> to correspond with the items displayed. We do this by
Xintercepting those messages to the superclass of class <List_Browser> and
Xhandle them in <List_Browser> so as to update the appropriate data:
X
X (send List_Browser :answer :ADD_ITEM '(item position)
X '(
X (setq items (array-insert-pos items (1- position) item))
X (send-super :add_item
X (send item :display_string)
X position)
X )
X )
X
X (send List_Browser :answer :ADD_ITEM_UNSELECTED '(item position)
X '(
X (setq items (array-insert-pos items (1- position) item))
X (send-super :add_item_unselected
X (send item :display_string)
X position)
X )
X )
X
X (send List_Browser :answer :DELETE_ITEM '(item)
X '(
X ;; this is too lame to implement... requires that we compare
X ;; item with the result of :display_string done on every elt
X ;; of ivar 'items'
X (error "Message :DELETE_ITEM not supported in List_Browser")
X )
X )
X
X (send List_Browser :answer :DELETE_POS '(position)
X '(
X (setq items (array-delete-pos items (1- position)))
X (send-super :delete_pos position)
X )
X )
X
XTo see how this subclassed list browser is used, and also to see how one
Xmight write a sample application in WINTERP using the object oriented
Xfeatures of XLISP, see ./winterp/examples/grep-br.lsp. That file
Ximplements a simple search browser based on the UN*X command 'grep'. See
Xalso ./winterp/examples/mail-br.lsp to see how you can build a simple
Xmh-based mail browser. Finally, as another example of subclassing Motif
Xwidgets, see ./winterp/examples/radiobox2.lsp.
X-------------------------------------------------------------------------------
X Niels Mayer -- hplabs!mayer -- mayer at hplabs.hp.com
X Human-Computer Interaction Department
X Hewlett-Packard Laboratories
X Palo Alto, CA.
X *
X
X
SHAR_EOF
if test 14611 -ne "`wc -c 'winterp.doc'`"
then
echo shar: error transmitting "'winterp.doc'" '(should have been 14611 characters)'
fi
echo shar: extracting "'xlisp.eg'" '(7724 characters)'
if test -f 'xlisp.eg'
then
echo shar: over-writing existing file "'xlisp.eg'"
fi
sed 's/^X//' << \SHAR_EOF > 'xlisp.eg'
XFrom sce!mitel!uunet!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim Fri Feb 16 07:17:21 EST 1990
XArticle: 73 of comp.lang.lisp.x
XPath: cognos!sce!mitel!uunet!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim
XFrom: tim at hpfcbig.SDE.HP.COM (Tim Mikkelsen)
XNewsgroups: comp.lang.lisp.x
XSubject: Re: intro to XLISP objects
XMessage-ID: <1170006 at hpfcbig.SDE.HP.COM>
XDate: 12 Feb 90 16:24:20 GMT
XReferences: <1170004 at hpfcbig.SDE.HP.COM>
XOrganization: HP SESD, Fort Collins, CO
XLines: 228
X
X
XA MORE REALISTIC EXAMPLE
X______________________________________________________________________________
X
X
XThe following is an example, using the idea of tools again. It contains
Xa hierarchy of tool classes. The top of the class hierarchy is TOOLS.
XHAND-TOOLS and SHOP-TOOLS are sub-classes of TOOLS. The example creates
Xinstances of these sub-classes. It is possible to extend this example
Xin various ways. One obvious extension would be to create a third tier
Xof classes under HAND-TOOLS that could contain classes like drills,
Xscrewdrivers, pliers and so on.
X
X
X
X
X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
X;
X; File name: tools.lsp
X; Author: Tim Mikkelsen
X; Description: Object-oriented example program
X; Language: XLISP 2.0
X;
X; Date Created: 10-Jan-1988
X; Date Updated: 2-Apr-1989
X;
X; (c) Copyright 1988, by Tim Mikkelsen, all rights reserved.
X; Permission is granted for unrestricted non-commercial use.
X;
X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
X
X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
X;
X; Define the superclasses and classes
X;
X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
X
X;
X; make TOOLS superclass
X; with a different :ISNEW method
X; added methods are :BORROW and :RETURN
X; class variables are NUMBER contains # of tool instances
X; ACTIVE-LIST contains list of current objects
X; instance variables are POWER list - (AC BATTERY HAND)
X; MOVEABLE CAN-CARRY or CAN-ROLL or FIXED
X; OPERATIONS list
X; MATERIAL list - (WOOD METAL PLASTIC ...)
X; PIECES list
X; LOCATION HOME or person's name
X;
X
X(setq tools (send class :new '(power
X moveable
X operations
X material
X pieces
X location)
X '(number active-list)))
X(send tools :answer :isnew '()
X '((if (null number) (setq number 1)
X (setq number (1+ number)))
X (setq active-list (cons self active-list))
X (setq location 'home)))
X(send tools :answer :borrow '(by-who)
X '((if (eq location 'home) (setq location by-who)
X (print "you can't"))))
X(send tools :answer :return '()
X '((if (eq location 'home) (print "got it already")
X (setq location 'home))))
X
X;
X; make HAND-TOOLS class
X; with a different :ISNEW method
X; new instance variable WEIGHT <number> of pounds
X; the rest is inherited from TOOLS
X;
X
X(setq hand-tools (send class :new '(weight) '() tools))
X(send hand-tools :answer :isnew '(pow op mat parts w-in)
X '((setq power pow)
X (setq moveable 'can-carry)
X (setq operations op)
X (setq material mat)
X (setq pieces parts)
X (setq weight w-in)
X (send-super :isnew)))
X
X;
X; make SHOP-TOOLS class
X; with a different :ISNEW method
X; no new instance variables
X; the rest is inherited from TOOLS
X;
X
X(setq shop-tools (send class :new '() '() tools))
X(send shop-tools :answer :isnew '(pow mov op mat parts)
X '((setq power pow)
X (setq moveable mov)
X (setq operations op)
X (setq material mat)
X (setq pieces parts)
X (send-super :isnew)))
X
X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
X;
X; Create instances of various tool classes
X;
X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
X
X(setq hand-drill (send hand-tools :new ; make an instance - HAND-DRILL
X '(ac)
X '(drill polish grind screw)
X '(wood metal plastic)
X '(drill drill-bits screw-bits buffer)
X '2.5))
X
X(setq table-saw (send shop-tools :new ; make an instance - TABLE-SAW
X '(ac)
X 'fixed
X '(rip cross-cut)
X '(wood plastic)
X '(saw blades fence)))
X
X
X(setq radial-arm (send shop-tools :new ; make an instance = RADIAL-ARM
X '(ac)
X 'can-roll
X '(rip cross-cut)
X '(wood plastic)
X '(saw blades dust-bag)))
X
X
XThe following session shows how to use the tool definitions from this
Xbetter example. The example starts at the OS shell and brings up xlisp
Xrunning the file 'tools.lsp'.
X
X ________________________________________________________________
X |
X | cmd? xlisp tools
X | ; loading "init.lsp"
X | ; loading "tools.lsp"
X | > (send hand-drill :borrow 'fred)
X | FRED
X |
X | > (send table-saw :return)
X | "got it already"
X | "got it already"
X |
X | > (send hand-drill :borrow 'joe)
X | "you can't"
X | "you can't"
X |
X | > (send hand-drill :return)
X | HOME
X |________________________________________________________________
X
X
XSo, Fred was able to borrow the HAND-DRILL. When an attempt was made to
Xreturn the TABLE-SAW, it was already at home. A second attempt to
Xborrow the HAND-DRILL indicated that "you can't" because it was already
Xlent out. Lastly, the HAND-DRILL was returned successfully. (Note that
Xthe "got it already" and "you can't" strings show up twice in the
Xdisplay because the methods both print and return the string.)
X
XThe following session shows the structure of the TOOLS object:
X
X ________________________________________________________________
X |
X | > (send tools :show)
X | Object is #<Object: #276fc>, Class is #<Object: #23fe2>
X | MESSAGES = ((:RETURN . #<Closure-:RETURN: #2dbd0>)
X | (:BORROW . #<Closure-:BORROW: #2ddba>)
X | (:ISNEW . #<Closure-:ISNEW: #274a4>))
X | IVARS = (POWER MOVEABLE OPERATIONS MATERIAL PIECES LOCATION)
X | CVARS = (NUMBER ACTIVE-LIST)
X | CVALS = #(3 (#<Object: #2cadc>
X | #<Object: #2cda2>
X | #<Object: #2d0e0>))
X | SUPERCLASS = #<Object: #23fd8>
X | IVARCNT = 6
X | IVARTOTAL = 6
X | #<Object: #276fc>
X |________________________________________________________________
X
X
XThe two TOOLS sub-classes HAND-TOOLS and SHOP-TOOLS structure looks like:
X
X ________________________________________________________________
X |
X | > (send hand-tools :show)
X | Object is #<Object: #2dab8>, Class is #<Object: #23fe2>
X | MESSAGES = ((:ISNEW . #<Closure-:ISNEW: #2d7a2>))
X | IVARS = (WEIGHT)
X | CVARS = NIL
X | CVALS = NIL
X | SUPERCLASS = #<Object: #276fc>
X | IVARCNT = 1
X | IVARTOTAL = 7
X | #<Object: #2dab8>
X |
X | > (send shop-tools :show)
X | Object is #<Object: #2d680>, Class is #<Object: #23fe2>
X | MESSAGES = ((:ISNEW . #<Closure-:ISNEW: #2d450>))
X | IVARS = NIL
X | CVARS = NIL
X | CVALS = NIL
X | SUPERCLASS = #<Object: #276fc>
X | IVARCNT = 0
X | IVARTOTAL = 6
X | #<Object: #2d680>
X |________________________________________________________________
X
X
XThe class HAND-TOOLS has an instance HAND-DRILL which looks like:
X
X ________________________________________________________________
X |
X | > (send hand-drill :show)
X | Object is #<Object: #2d0e0>, Class is #<Object: #2dab8>
X | WEIGHT = 2.5
X | POWER = (AC)
X | MOVEABLE = CAN-CARRY
X | OPERATIONS = (DRILL POLISH GRIND SCREW)
X | MATERIAL = (WOOD METAL PLASTIC)
X | PIECES = (DRILL DRILL-BITS SCREW-BITS BUFFER)
X | LOCATION = HOME
X | #<Object: #2d0e0>
X |________________________________________________________________
X
X
SHAR_EOF
if test 7724 -ne "`wc -c 'xlisp.eg'`"
then
echo shar: error transmitting "'xlisp.eg'" '(should have been 7724 characters)'
fi
echo shar: extracting "'xlisp.ref'" '(3263 characters)'
if test -f 'xlisp.ref'
then
echo shar: over-writing existing file "'xlisp.ref'"
fi
sed 's/^X//' << \SHAR_EOF > 'xlisp.ref'
XFrom sce!mitel!uunet!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim Mon Jan 8 09:06:27 EST 1990
XArticle: 2222 of comp.lang.lisp
XPath: cognos!sce!mitel!uunet!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim
XFrom: tim at hpfcbig.SDE.HP.COM (Tim Mikkelsen)
XNewsgroups: comp.lang.lisp
XSubject: Re: XLISP 2.0 reference available
XMessage-ID: <6950018 at hpfcbig.SDE.HP.COM>
XDate: 6 Jan 90 04:33:30 GMT
XReferences: <6950014 at hpfcbig.SDE.HP.COM>
XOrganization: HP SESD, Fort Collins, CO
XLines: 19
X
XAn accessable ftp machine!
X
XThe XLISP 2.0 reference has been made available for anonymous FTP on
Xhost cs.orst.edu, in the pub/xlisp directory, file xlispref.txt (a plain
XASCII text file, roughly 412k in size). It is requested that you
Xretrieve this file ONLY during non-working hours (say 7pm to 7am,
XPacific Time).
X
XI've tested access to this machine and the file and I was able to get at
Xit. As mentioned the file is large, so it took about 9 minutes to get
Xthe entire file at 8 PM.
X
X
XThanks to Marion Hakanson (hakanson at cse.ogi.edu) for getting this put on
Xcs.orst.edu. There will be a few other machines that the reference will
Xbe ftp'able from (including simtel20). I'll post these new machines on
Xcomp.lang.lisp.x (which is probably where this note should have gone).
X
XTim Mikkelsen
X
X
XFrom sce!mitel!uunet!visdc!jiii Mon Jan 8 09:06:33 EST 1990
XArticle: 2223 of comp.lang.lisp
XPath: cognos!sce!mitel!uunet!visdc!jiii
XFrom: jiii at visdc.UUCP (John E Van Deusen III)
XNewsgroups: comp.lang.lisp
XSubject: Re: XLISP 2.0 reference available
XSummary: sed script for reformatting
XMessage-ID: <726 at visdc.UUCP>
XDate: 6 Jan 90 19:58:28 GMT
XReferences: <6950014 at hpfcbig.SDE.HP.COM> <6950017 at hpfcbig.SDE.HP.COM>
XReply-To: jiii at visdc.UUCP (John E Van Deusen III)
XOrganization: VI Software Development, Boise, Idaho
XLines: 70
X
XTo everyone who has obtained Tim Mikkelsen's excellent and very
Xuseful XLISP Reference in ASCII format, the following sed script
Xmight be of interest to you. It slightly reformats the document
Xso that when piped through pr(1), there are no empty pages. It
Xalso keeps the text within reasonable margins for printing on
X8.5x11" paper, and provides some additional consistency in tabbing
Xand line spacing.
X
XAssuming that you have the files ref1.Z, ref2.Z, ref3.Z, ref4.Z,
Xand ref5.Z as provided by Tim Mikkelsen, and the sed script
Xcontained here has been saved as sedf; the following command, or a
Xvariation, will produce the reformatted document in the file prt:
X
X$ zcat ref[1-5].Z | sed -f sedf | pr -h "XLISP Reference" > prt
X
X--
XJohn E Van Deusen III, PO Box 9283, Boise, ID 83707, (208) 343-1865
X
Xuunet!visdc!jiii
X
X===cut here===
X/^[]$/,${
X s/^[ ] / /
X s/^ / /
X s/^ [ ]/ /
X /^ /s/^ */ /
X /^[ ][ ]* [ ][ ]*/s/ //
X /^EXAMPLES$/,/^[^ ]/{
X /^[ ]*$/d
X /^ /!{
X /^EXAMPLES$/a\
X
X /^EXAMPLES$/!{
X /^[]/!i\
X
X }
X
X }
X s/^ //
X }
X /^SYNTAX$/,/^DESCRIPTION$/{
X /^[ ][ ]*<.*>.*-/,/^$/{
X s/- *[ ]/- /
X />.*- /!{
X /^[ ][ ]* /!{
X s/^[ ][ ]*/& /
X }
X s/^ //
X }
X }
X }
X /^DESCRIPTION$/,/^EXAMPLES$/{
X s/ */ /g
X s/\. /\. /g
X }
X /^[A-Z][A-Z ]*:/,/^$/{
X s/ */ /g
X s/\. /\. /g
X }
X /^$/,/^..*/{
X /^$/d
X /^[]$/!i\
X
X }
X /^[]$/,/^.*/{
X /^[]$/d
X /^$/d
X /^.*$/s/^.*$/&/
X }
X}
X
X
SHAR_EOF
if test 3263 -ne "`wc -c 'xlisp.ref'`"
then
echo shar: error transmitting "'xlisp.ref'" '(should have been 3263 characters)'
fi
echo shar: extracting "'xlisp.txt'" '(15230 characters)'
if test -f 'xlisp.txt'
then
echo shar: over-writing existing file "'xlisp.txt'"
fi
sed 's/^X//' << \SHAR_EOF > 'xlisp.txt'
XFrom sce!mitel!uunet!snorkelwacker!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim Fri Feb 16 07:18:45 EST 1990
XArticle: 74 of comp.lang.lisp.x
XPath: cognos!sce!mitel!uunet!snorkelwacker!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim
XFrom: tim at hpfcbig.SDE.HP.COM (Tim Mikkelsen)
XNewsgroups: comp.lang.lisp.x
XSubject: Re: intro to XLISP objects
XMessage-ID: <1170005 at hpfcbig.SDE.HP.COM>
XDate: 12 Feb 90 16:23:48 GMT
XReferences: <1170004 at hpfcbig.SDE.HP.COM>
XOrganization: HP SESD, Fort Collins, CO
XLines: 434
X
X
X
X
X
X
X
X
X
X
X
X
X XLISP 2.0 OBJECTS PRIMER
X
X
X by
X
X Tim I Mikkelsen
X
X
X February 3, 1990
X
X
X
X
X
X
X
X
X Copyright (c) 1990 by Tim I. Mikkelsen. All Rights Reserved.
X No part of this document may be copied, reproduced or translated
X for commercial use without prior written consent of the author.
X Permission is granted for non-commercial use as long as this
X notice is left intact.
X
X
X ________________________________________________________________
X
X
X One of the features in the design of XLISP is object-oriented
X programming. This primer is intended to serve as a very brief
X introduction to the object facilities of the XLISP 2.0 dialect
X of LISP. Note that the object features of XLISP are not based
X on other existing object definitions in other LISP dialects. If
X you find problems in the primer, I'd appreciate hearing.
X
X
X Tim Mikkelsen
X 4316 Picadilly Drive
X Fort Collins, Colorado 80526
X
X
X
XPROGRAMMING STYLES
X______________________________________________________________________________
X
X
XThere are many programming paradigms (models). Some of the paradigms
Xare procedural, functional, rule-based, declarative and object-oriented.
XA language can have aspects of one or many of these programming models.
X
X
XProcedure-Oriented
X
XThe programming paradigm most people are familiar with is the procedural
Xstyle. The primitives in procedural programming are: subroutines and
Xdata structures. Through these primitives, programmers have some
Xlimited abilities to share programs and program fragments. C and Pascal
Xare examples of procedural languages. Some procedural languages (such
Xas Modula and ADA) have extensions that provide for better sharing of
Xcode.
X
X
XObject-Oriented Programming
X
XObject-oriented programming is based on the primitives of objects,
Xclasses and messages. Objects are defined in terms of classes. Actions
Xoccur by sending a message to an object. An object's definition can be
Xinherited from more general classes. Objective-C and C++ both are
Xobject-oriented dialects of the C language. Many dialects of LISP have
Xsome object oriented extension (Flavors, Common LOOPS, CLOS and others).
XThere currently is standards work proceeding to add object-oriented
Xprogramming to Common LISP.
X
X
XObject Oriented Programming
X
XSo, the object-oriented programming model is based around the concepts
Xof objects, classes and messages. An object is essentially a black box
Xthat contains internal state information. You send an object a message
Xwhich causes the object to perform some operation. Objects are defined
Xand described through classes.
X
XOne aspect of an object is that you do not have to know what is inside -
Xor how it works - to be able to use it. From a programming point of
Xview, this is very handy. You can develop a series of objects for
Xsomeone to use. If you need to change what goes on inside, the users of
Xthe objects should be unaware.
X
XAnother aspect of objects is that of inheritance. You can build up new
Xclasses from existing classes by inheriting the existing class's
Xfunctionality and then extending the new definition. For example, you
Xcan define a tool class (with various attributes) and then go about
Xcreating object instances tool-1, tool-2, and so on. You can also
Xcreate new sub-classes of the tool class like power-tool. This is also
Xvery handy because you don't have to re-implement something if you can
Xbuild it up from existing code.
X
X
X
X
XXLISP OBJECT-ORIENTED PROGRAMMING
X______________________________________________________________________________
X
X
X
XXLISP OBJECT TERMINOLOGY
X
XThere are, as previously mentioned, many different languages with
Xobject-oriented extensions and facilities. The terminology, operations
Xand styles of these are very different. Some of the main definitions
Xfor XLISP's object-oriented extensions are:
X
X Object data type The OBJECT DATA TYPE is a built-in data
X type of XLISP. Members of the object
X data type are object instances and
X classes.
X
X Object instances An OBJECT INSTANCE is a composite
X structure that contains internal state
X information, methods (the code which
X respond to messages), a pointer to the
X object instance's defining class and a
X pointer to the object's super-class.
X XLISP contains no built-in object
X instances.
X
X Class objects A CLASS OBJECT is, essentially, the
X template for defining the derived object
X instances. A class object, although
X used differently from a simple object
X instance, is structurally a member of
X the object data type. It is also
X contains the linking mechanism that
X allows you to build class hierarchies
X (sub-classes and super-classes). XLISP
X contains two built-in class objects:
X OBJECT and CLASS.
X
X Message selector The MESSAGE SELECTOR is the symbol that
X is used to select a particular action
X (Method) from the object.
X
X Message The MESSAGE is the combination of the
X message selector and the data (if any)
X to be sent to the object.
X
X Method The METHOD is the actual code that gets
X executed when the object receives the
X Message.
X
X
X
XSENDING MESSAGES
X
XThe mechanism for sending messages to XLISP objects is via the SEND
Xfunction. It takes an object, a message selector and various optional
Xarguments (depending on the message selector).
X
XThe way that a user creates a new object is to send a :NEW message to a
Xpreviously defined class. The result of this SEND will return an
Xobject, so this is normally preceded by a SETQ. The values shown in the
Xexamples that follow may not match what you see if you try this on your
Xversion of XLISP - this is not an error. The screens that are used in
Xthe various examples are similar to what you should see on your computer
Xscreen. The ">" is the normal XLISP prompt (the characters that follow
Xthe prompt is what you should type in to try these examples).
X
X
X ________________________________________________________________
X |
X | > (setq my-object (send object :new))
X | #<Object: #2e100>
X |________________________________________________________________
X
X
XThe object created here is of limited value. Most often, you create a
Xclass object and then you create instances of that class. So in the
Xfollowing example, a class called MY-CLASS is created that inherits its
Xdefinition from the a built-in CLASS definition. Then two instances are
Xcreated of the new class.
X
X ________________________________________________________________
X |
X | > (setq my-class (send class :new '()))
X | #<Object: #27756>
X |
X | > (setq my-instance (send my-class :new))
X | #<Object: #27652>
X |
X | > (setq another-instance (send my-class :new))
X |#<Object: #275da>
X |________________________________________________________________
X
X
X
XCLASSES
X
XPreviously, a :NEW message was used to create an object. The message
Xused to see what is in an object is the :SHOW message.
X
X ________________________________________________________________
X |
X | > (send my-class :show)
X | Object is #<Object: #27756>, Class is #<Object: #23fe2>
X | MESSAGES = NIL
X | IVARS = NIL
X | CVARS = NIL
X | CVALS = NIL
X | SUPERCLASS = #<Object: #23fd8>
X | IVARCNT = 0
X | IVARTOTAL = 0
X | #<Object: #27756>
X |________________________________________________________________
X
X
XFrom the display of the MY-CLASS object you can see there are a variety
Xof components. The components of a class are:
X
X Class Pointer This pointer shows to what class the
X object (instance or class) belongs. For
X a class, this always points to the
X built-in object CLASS. This is also
X true of the CLASS object, its class
X pointer points to itself.
X
X Superclass Pointer This pointer shows what the next class
X up the class hierarchy is. If the user
X does not specify what class is the
X superclass, it will point to the
X built-in class OBJECT.
X
X Messages This component shows what messages are
X allowed for the class, and the
X description of the method that will be
X used. If the method is system-defined,
X it will show up in the form of '#<Subr-:
X #18b98>'. Remember that the class
X hierarchy (through the Superclass
X Pointer) is searched if the requested
X message is not found in the class.
X
X Instance Variables This component lists what instance
X variables will be created when an object
X instance is created. If no instances of
X the class exist, there are no Instance
X Variables. If there are 5 instances of
X a class, there are 5 complete and
X different groups of the Instance
X Variables.
X
X Class Variables The CLASS VARIABLES (CVAR) component
X and Values lists what class variables exist within
X the class. The Class Values (CVAL)
X component shows what the current values
X of the variables are. Class Variables
X are used to hold state information about
X a class. There will be |Bone of each|A
X of the Class Variables, independent of
X the number of instances of the class
X created.
X
XA BETTER EXAMPLE
X
XThe example previously shown does work, but the class and instances
Xcreated don't really do anything of interest. The following example
Xsets up a tool class and creates some tool instances.
X
X ________________________________________________________________
X |
X | > (setq my-tools (send class :new '(power moveable operation)))
X | #<Object: #277a6>
X |
X | > (send my-tools :answer :isnew '(pow mov op)
X | '((setq power pow)
X | (setq moveable mov)
X | (setq operation op)))
X | #<Object: #277a6>
X |
X | > (setq drill (send my-tools :new 'AC t 'holes))
X | #<Object: #2ddbc>
X |
X | > (setq hand-saw (send my-tools :new 'none t 'cuts))
X | #<Object: #2dc40>
X |
X | > (setq table-saw (send my-tools :new 'AC nil 'cuts))
X | #<Object: #2db00>
X |________________________________________________________________
X
X
XSo, a class of objects called MY-TOOLS was created. Note that the class
Xobject MY-TOOLS was created by sending the :NEW message to the built-in
XCLASS object. Within the MY-TOOL class, there are three instances
Xcalled DRILL, HAND-SAW and TABLE-SAW. These were created by sending the
X:NEW message to the MY-TOOLS class object. Notice that the parameters
Xfollowed the message selector.
X
X
XINSTANCES
X
XThe following is a display of the contents of some of the previously
Xcreated instances:
X
X ________________________________________________________________
X |
X | > (send drill :show)
X | Object is #<Object: #2ddbc>, Class is #<Object: #277a6>
X | POWER = AC
X | MOVEABLE = T
X | OPERATION = HOLES
X | #<Object: #2ddbc>
X |
X | > (send hand-saw :show)
X | Object is #<Object: #2dc40>, Class is #<Object: #277a6>
X | POWER = NONE
X | MOVEABLE = T
X | OPERATION = CUTS
X | #<Object: #2dc40>
X |________________________________________________________________
X
X
XFrom the display of these instances you can see there are some
Xcomponents and values. The components of an instance are:
X
X Class Pointer This pointer shows to which class the
X current object instance belongs. It is
X through this link that the system finds
X the methods to execute for the received
X messages.
X
X Instance Variables The Instance Variables (IVAR) component
X and Values lists what variables exist within the
X instance. The Instance Values component
X holds what the current values of the
X variables are. Instance Variables are
X used to hold state information for each
X instance. There will be a group of
X Instance Variables for each instance.
X
X
X
X
XMETHODS
X
XThere have been a few of the messages and methods in XLISP shown to this
Xpoint (:NEW and :SHOW). The following are the methods built into XLISP:
X
X :ANSWER The :ANSWER method allows you to define or
X change methods within a class.
X
X :CLASS The :CLASS method returns the class of an object.
X
X :ISNEW The :ISNEW method causes an instance to run its
X initialization code. When the :ISNEW method is
X run on a class, it resets the class state. This
X allows you to re-define instance variables,
X class variables, etc.
X
X :NEW The :NEW method allows you to create an instance
X when the :NEW message is sent to a user-defined
X class. The :NEW method allows you to create a
X new class (when the :NEW message is sent to the
X built-in CLASS).
X
X :SHOW The :SHOW method displays the instance or class.
X
X
X
XSENDING MESSAGES TO A SUPERCLASS
X
XIn addition to the SEND function, there is another function called
XSEND-SUPER. The SEND-SUPER function causes the specified message to be
Xperformed by the superclass method. This is a mechanism to allow
Xchaining of methods in a class hierarchy. This chaining behavior can be
Xachieved by creating a method for a class with the :ANSWER message.
XWithin the body of the method, you include a SEND-SUPER form. This
Xfunction is allowed only inside the execution of a method of an object.
X
X
XOBJECT AND CLASS
X
XThe definition of the built-in class OBJECT is:
X
X ________________________________________________________________
X |
X | > (send object :show)
X | Object is #<Object: #23fd8>, Class is #<Object: #23fe2>
X | MESSAGES = ((:SHOW . #<Subr-: #23db2>)
X | (:CLASS . #<Subr-: #23dee>)
X | (:ISNEW . #<Subr-: #23e2a>))
X | IVARS = NIL
X | CVARS = NIL
X | CVALS = NIL
X | SUPERCLASS = NIL
X | IVARCNT = 0
X | IVARTOTAL = 0
X | #<Object: #23fd8>
X |________________________________________________________________
X
X
XNote that OBJECT is a class - as opposed to an "instance-style" object.
XOBJECT has no superclass, it is the top or root of the class hierarchy.
XOBJECT's class is CLASS.
X
X ________________________________________________________________
X |
X | > (send class :show)
X | Object is #<Object: #23fe2>, Class is #<Object: #23fe2>
X | MESSAGES = ((:ANSWER . #<Subr-: #23e48>)
X | (:ISNEW . #<Subr-: #23e84>)
X | (:NEW . #<Subr-: #23ea2>))
X | IVARS = (MESSAGES IVARS CVARS CVALS SUPERCLASS
X | IVARCNT IVARTOTAL)
X | CVARS = NIL
X | CVALS = NIL
X | SUPERCLASS = #<Object: #23fd8>
X | IVARCNT = 7
X | IVARTOTAL = 7
X | #<Object: #23fe2>
X |________________________________________________________________
X
X
XCLASS has a superclass of OBJECT. It's class is itself - CLASS.
X
X
X
X
SHAR_EOF
if test 15230 -ne "`wc -c 'xlisp.txt'`"
then
echo shar: error transmitting "'xlisp.txt'" '(should have been 15230 characters)'
fi
# End of shell archive
exit 0
--
Gary Murphy uunet!mitel!sce!cognos!garym
(garym%cognos.uucp at uunet.uu.net)
(613) 738-1338 x5537 Cognos Inc. P.O. Box 9707 Ottawa K1G 3N3
"There are many things which do not concern the process" - Joan of Arc
More information about the Comp.sources.misc
mailing list