Home Segments Index Top Previous Next

625: Mainline

Now that you know about points, you can understand the difference between identity and equality.

Two variables with point assignments satisfy the == predicate, and are said to have identical values, if they both refer to the same point. In the following illustration, the second test answers false, because the @ method produces a distinct point each time that it is sent, and distinct points with the same x and y values are still distinct points.

Point method definition • instance 
testForIdentity: aPoint 
  Transcript show: (self == self) printString; cr; 
             show: (self == aPoint) printString; cr. 
Workspace
3 @ 4 testForIdentity: 3 @ 4 
Transcript 
true 
false 

On the other hand, two variables with point assignments satisfy the = predicate, and are said to have equal values, if they both refer to points that have the same x and y values. Thus, both of the tests answer true in the following illustration:

Point method definition • instance 
testForEquality: aPoint 
  Transcript show: (self = self) printString; cr; 
             show: (self = aPoint) printString; cr. 
Workspace
3 @ 4 testForEquality: 3 @ 4 
Transcript 
true 
true