This preview shows page 1. Sign up to view the full content.
Unformatted text preview: CS 61A Lecture Notes Week 6 Topic: Generic operators Reading: Abelson & Sussman, Sections 2.4 through 2.5.2 (pages 169200) The overall problem were 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, well use another example about geometric shapes.Just to get away from the arithmetic examples in the text, well use another example about geometric shapes....
View Full Document
- Spring '10