


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Professor: Swigger; Class: Symbolic Processing; Subject: Computer Science/Computer Engineering; University: University of North Texas; Term: Unknown 2009;
Typology: Lab Reports
1 / 4
This page cannot be seen from the preview
Don't miss anything!



There are some built in class functions that can help you access information about the classes and instances. Load your lab assignment and try the following. In the exercises, watch your ‘ You can find the “name” of a class by typing: ((FIND-CLASS class-name) -> class
(clos::class-precedence-list (find-class 'zebra)) (#<STANDARD-CLASS ZEBRA 200953DF> #<STANDARD-CLASS HERBIVORE 200EF317> #<STANDARD-CLASS MAMMAL 2009ADD3> #<STANDARD-CLASS STANDARD-OBJECT 203EE70F> #<BUILT-IN-CLASS T 2042EB13>) This gives you a list of all the classes that are zebra inherits. Now, you can combine this function with one of the previous functions to see if an class is in the class precedence list. As in: (member (find-class ‘mammal) (clos::class-precedence-list (find-class ‘zebra))) It will return a bunch of stuff, but when you use this in a program, it will be interpreted as “t” There is also a way to see the JUST the direct uperclass of a class – As in (clos::class-direct-superclasses (find-class ‘zebra)) OTHER HELPFUL functions. (describe ‘zebra) – returns a bunch of stuff, along with the slots and values for the class. This will allow you to verify that you have what you think you have. (type-of tony) --- returns the name of the class of an instance (class-of tony) --- returns the class object of an instance (equalp (class-of tony) (class-of freda)) – returns t or nil if two superclasses of instances are equal Returns t if the two classes are equal (typep Freda mammal ) -- returns t if Freda has a mammal in her superclass list.
To specify a subclass of something with NO properties, you enter <defclass name (superclass)())> as in (defclass duck (mammal) ()) Often we put the “name” as a slot value for instance because then we can do an (eval name) to get the manipulate the object itself. Placing Functions into Slots You may recall that I said that we could put functions into slots. We can do it in two ways. (1) We can put a function directly into a slot, just like a text. For example, modify the Man class and create a new slot called “talk” which contains a function that prints out different things. (defclass man (human) ((name :initarg :name :accessor get-name) (occupation :initarg :occupation :accessor get-job) (talk :initform '(nth (random 2) '((I am here)(I am there)(I am everywhere))) ))) Now, re-create JOE the plumber as a new instance. (setf joe (create-man 'joe 'plumber )) You can make joe talk by typing: (eval (slot-value sam ‘talk)) *The LISP random isn’t very good….. Another way to do this is to put JUST the function name into the man class. For example: (defclass man (human) ((name :initarg :name :accessor get-name) (occupation :initarg :occupation :accessor get-job) (talk :initform 'talk ))) Now you need a function called talk. (defun talk () (nth (random 2) '((I am here)(I am there) (I am everywhere)))) Create joe again, and enter the following: =>(setf joe (create-man 'joe 'plumber )) => (funcall (slot-value joe ‘talk)) Joe will talk again…… Making queries -- THIS IS WHAT YOU WILL BE HANDING IN: ***Note that by