Object 2 Laboratory - Symbolic Processing | CSCE 3210, Lab Reports of Computer Science

Material Type: Lab; Professor: Swigger; Class: Symbolic Processing; Subject: Computer Science/Computer Engineering; University: University of North Texas; Term: Unknown 2009;

Typology: Lab Reports

Pre 2010

Uploaded on 08/18/2009

koofers-user-j2o
koofers-user-j2o 🇺🇸

9 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Object 2 Lab
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
As in:
<cl> (FIND-CLASS 'zebra)
#<STANDARD-CLASS ZEBRA {90374C5}>
This returns the “object.” To get the “name” of the object, type:
(CLASS-NAME class) -> symbol
As in:
<cl> (class-name (find-class 'zebra))
ZEBRA
You’re probably wondering how this can be of value? Well, you generally use in conjunction with other
types of functions. For example, if you need to find out if an object is actually part of another class, you
might combine with this built-in function
(CLOS::CLASS-PRECEDENCE-LIST class)
As in:
(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.
pf3
pf4

Partial preview of the text

Download Object 2 Laboratory - Symbolic Processing | CSCE 3210 and more Lab Reports Computer Science in PDF only on Docsity!

Object 2 Lab

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

As in:

(FIND-CLASS 'zebra) #<STANDARD-CLASS ZEBRA {90374C5}> This returns the “object.” To get the “name” of the object, type: (CLASS-NAME class) -> symbol

As in:

(class-name (find-class 'zebra)) ZEBRA You’re probably wondering how this can be of value? Well, you generally use in conjunction with other types of functions. For example, if you need to find out if an object is actually part of another class, you might combine with this built-in function (CLOS::CLASS-PRECEDENCE-LIST class)

As in:

(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

  1. or anything else should just be eval…. Finally, the DRIVER Driver function should: set up dummy variable for the query Print something that says hello loop Ask the user to enter a query sets the query to a variable prints the (call to the process query)) end loop. When finished, upload your file to query-lab.