Download presentation
Presentation is loading. Please wait.
1
Common Lisp! John Paxton Montana State University Summer 2003
2
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.
3
CLOS Common Lisp Object System Objects Methods Inheritance
4
Class Declaration (defclass city () ( (name :accessor name) (country :accessor country) (population :accessor population) )
5
Class Instantiation > (setf bozeman (make-instance 'city)) #
6
Accessing Data Fields > (setf (name bozeman) 'bozeman) BOZEMAN > (setf (country bozeman) 'usa) USA > (setf (population bozeman) 30000) 30000
7
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)) )
8
Calling Methods > (my-print bozeman) The city's name is BOZEMAN The city's country is USA
9
Using Inheritance (defclass montana-city (city) ( (culture-level :accessor culture-level) )
10
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)
11
Using Inheritance > (my-print two-dot) The city's name is TWO-DOT The city's country is USA
12
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)) )
13
Using Inheritance > (my-print two-dot) The city's name is TWO-DOT The city's culture-level is LOW
14
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.
15
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.