Common Lisp! John Paxton Montana State University Summer 2003
Bozeman Facts John Bozeman came west in search of gold. For a while, he guided settlers west in covered wagon trains. In 1863, he entered the Gallatin Valley for the first time and established Bozeman.
CLOS Common Lisp Object System Objects Methods Inheritance
Class Declaration (defclass city () ( (name :accessor name) (country :accessor country) (population :accessor population) )
Class Instantiation > (setf bozeman (make-instance 'city)) #
Accessing Data Fields > (setf (name bozeman) 'bozeman) BOZEMAN > (setf (country bozeman) 'usa) USA > (setf (population bozeman) 30000) 30000
Writing Methods (defmethod my-print ((some-city city)) (format t "The city's name is ~a~%" (name some-city)) (format t "The city's country is ~a~%“ (country some-city)) )
Calling Methods > (my-print bozeman) The city's name is BOZEMAN The city's country is USA
Using Inheritance (defclass montana-city (city) ( (culture-level :accessor culture-level) )
Using Inheritance > (setf two-dot (make-instance 'montana-city)) # > (setf (name two-dot) 'two-dot) > (setf (country two-dot) ‘usa) > (setf (population two-dot) 172) > (setf (culture-level two-dot) 'low)
Using Inheritance > (my-print two-dot) The city's name is TWO-DOT The city's country is USA
Using Inheritance (defmethod my-print ((some-city montana-city)) (format t "The city's name is ~a~%" (name some-city)) (format t "The city's culture-level is ~a~%“ (culture-level some-city)) )
Using Inheritance > (my-print two-dot) The city's name is TWO-DOT The city's culture-level is LOW
Questions 1.Use CLOS to define a class named generic-list. This class should have methods called make-empty, is-empty, insert-item and remove-item. Insert-item and remove-item should both operate from the front of the list. Demonstrate that the class works.
Questions 2.Define a class called stack. Inherit as many methods as possible. 3.Define a class called queue. Inherit as many methods as possible.