This preview shows page 1. Sign up to view the full content.
Unformatted text preview: (she said she said) Besides having a variable for each instance, its also possible to have variables that are shared by every instance of the same class: ;;;;; In file cs61a/lectures/3.0/demo1.scm (define-class (counter) (instance-vars (count 0)) (class-vars (total 0)) (method (next) (set! total (+ total 1)) (set! count (+ count 1)) (list count total))) > (define c1 (instantiate counter)) > (ask c1 next) (1 1) > (ask c1 next) (2 2) > (define c2 (instantiate counter)) > (ask c2 next) (1 3) > (ask c1 next) (3 4) Now each next message tells us both the count for this particular counter and the overall count for all counters combined. To understand the idea of inheritance, well rst dene a person class that knows about talking in various ways, and then dene a pigger class thats just like a person except for talking in Pig Latin: 313...
View Full Document
- Spring '10