Unformatted text preview: The book uses pairs to represent many different abstract data types: rational numbers (numerator and denominator), complex numbers (real and imaginary parts), points ( x and y coordinates), intervals (low and high bounds), and line segments (two endpoints). Notice that in the case of line segments we think of the representation as one pair containing two points, not as three pairs containing four numbers. (That’s what it means to respect a data abstraction.) Note: What’s the difference between these two: (define (makerat num den) (cons num den)) (define makerat cons) They are both equally good ways to implement a constructor for an abstract data type. The second way has a slight speed advantage (one fewer function call) but the first way has a debugging advantage because you can trace makerat without tracing all invocations of cons . • Data aggregation doesn’t have to be primitive....
View
Full Document
 Spring '10
 Harvey,B
 ObjectOriented Programming, Type system, Type theory, cons num den

Click to edit the document details