How to Design Programs: An Introduction to Programming and Computing

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
How to Design Programs: An Introduction to Computing and Programming [Go to first , previous , next page; contents ; index ] Section 42 Equality As we mutate structures or vectors, we use words such as ``the vector now contains false in its first field'' to describe what happens. Behind those words is the idea that the vector itself stays the same -- even though its properties change. What this observation suggests is that there are really two notions of equality: the one we have used so far and a new one based on effects on a structure or vector. Understanding these two notions of equality is critically important for a programmer. We therefore discuss them in detail in the following two subsections. 42.1 Extensional Equality Recall the class of posn structures from part I . A posn combines two numbers; its fields are called x and y . Here are two examples: (make-posn 3 4) (make-posn 8 6) They are obviously distinct. In contrast, the following two (make-posn 12 1) (make-posn 12 1) are equal. They both contain 12 in the x -field and 1 in the y -field. More generally, we consider two structures to be equal if they contain equal components. This assumes that we know how to compare the components, but that's not surprising. It just reminds us that processing structures follows the data definition that comes with the structure definition. Philosophers refer to this notion of equality as EXTENSIONAL EQUALITY . Section 17.8 introduced extensional equality and discussed its use for building tests. As a reminder, let's consider a function for determining the extensional equality of posn structures: ;; equal-posn : posn posn -> boolean ;; to determine whether two posns are extensionally equal (define (equal-posn p1 p2) (1 of 6) [2/5/2008 4:59:50 PM]
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon