Unformatted text preview: CS 61A Lecture Notes Week 6 Topic: Generic operators Reading: Abelson & Sussman, Sections 2.4 through 2.5.2 (pages 169–200) The overall problem we’re addressing this week is to control the complexity of large systems with many small procedures that handle several types of data. We are building toward the idea of object-oriented programming , which many people see as the ultimate solution to this problem, and which we discuss for two weeks starting next week. Big ideas: • tagged data • data-directed programming • message passing The first problem is keeping track of types of data. If we see a pair whose car is 3 and whose cdr is 4, does that represent 3 4 or does it represent 3 + 4 i ? The solution is tagged data : Each datum carries around its own type information. In effect we do (cons ’rational (cons 3 4)) for the rational number 3 4 , although of course we use an ADT. Just to get away from the arithmetic examples in the text, we’ll use another example about geometric shapes.Just to get away from the arithmetic examples in the text, we’ll use another example about geometric shapes....
View Full Document
- Spring '10
- ULTIMATE SOLUTION, unknown shape, type-tag shape