This preview shows pages 1–3. Sign up to view the full content.
How to Design Programs: An Introduction to Computing and Programming [Go to first, previous, next page; contents; index]Section 42EqualityAs we mutate structures or vectors, we use words such as ``the vector now contains falsein 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 EqualityRecall the class of posnstructures from part I. A posncombines two numbers; its fields are called xand 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 12in the x-field and 1in 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 EXTENSIONALEQUALITY. 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 posnstructures: ;; 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]
has intentionally blurred sections.
Sign up to view the full version.