Lecture overview -- Keyboard shortcut: 'u'  Previous page: Classes and objects -- Keyboard shortcut: 'p'  Next page: Example of the general class pattern -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Lecture 8 - Page 6 : 11
Functional Programming in Scheme
Object-oriented programming in Scheme
A general pattern of classes

The following shows a template of a function that serves as a class

(define (class-name construction-parameters)
 (let ((instance-var init-value)
        ...)
     
   (define (method parameter-list)
     method-body)

   ...
     
   (define (self message)
     (cond ((eqv? message selector) method)
	   ...
             
	   (else (error "Undefined message" message))))
     
   self))

A general template of a simulated class. construction-parameters are typically transferred to the let construct, which we want to play the role as instance variables. Next comes explicitly defined methods, and last is the object handle called self . Notice that the value returned by the class is the value of self - the object handle.

y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/class-template-functions.scmAccompanying functions for instantiation and message passing.