Common Lisp - PowerPoint PPT Presentation

About This Presentation
Title:

Common Lisp

Description:

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. ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 16
Provided by: Joh7
Category:
Tags: common | lisp | wagon

less

Transcript and Presenter's Notes

Title: Common Lisp


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
  • gt (setf bozeman (make-instance 'city))
  • ltCITY x20383741gt

6
Accessing Data Fields
  • gt (setf (name bozeman) 'bozeman)
  • BOZEMAN
  • gt (setf (country bozeman) 'usa)
  • USA
  • gt (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
  • gt (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
  • gt (setf two-dot (make-instance
  • 'montana-city))
  • ltMONTANA-CITY x203BDA7Dgt
  • gt (setf (name two-dot) 'two-dot)
  • gt (setf (country two-dot) usa)
  • gt (setf (population two-dot) 172)
  • gt (setf (culture-level two-dot) 'low)

11
Using Inheritance
  • gt (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
  • gt (my-print two-dot)
  • The city's name is TWO-DOT
  • The city's culture-level is LOW

14
Questions
  • 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
  • Define a class called stack. Inherit as many
    methods as possible.
  • Define a class called queue. Inherit as many
    methods as possible.
Write a Comment
User Comments (0)
About PowerShow.com