# Examples 8.1.2.2:
ELT_EQ

The single feature of the required library class ELT_EQ is used in individual examples below. None of the examples given is a complete class nor necessarily a 'complete' method.

In all of the examples it will be assumed that the code shown is in a class called, say, EXAMPLE.

#### elt_eq

This feature provides a test for equality which is based either on value equality (if the object derives from $IS_EQ) or object equality - if not immutable! Consider the following four example cases -

first : CARD := 42 ;
second : CARD := 27 ;
res : BOOL := elt_eq(first,second)

which is valid because the type CARD derives from $IS_EQ and gives res the value false. Contrast this with -

first : ARRAY{CARD} ;
second : ARRAY{CARD} ;
res : BOOL := elt_eq(first,second)

which makes res also false - but this time because neither are objects - they have not yet been created! This kind of error is very easy to fall into, even for quite experienced O-O programmers! Look, however, at the next example -

first : ARRAY{CARD} := ARRAY{CARD}::create(5) ;
second : ARRAY{CARD} := ARRAY{CARD}::create(5) ;
res : BOOL := elt_eq(first,second)

What is the value of res under these circumstances? There are two created objects - although they do not themselves have an equality test. Contrast that with -

first : ARRAY{CARD} := ARRAY{CARD}::create(5) ;
second : ARRAY{CARD} := first ;
res : BOOL := elt_eq(first,second)

for which, at last, res is true - because they are the same object! (Oh! By the way! That must mean that res was false in the previous example!)

| Specification Index |  | Language Index |  | Section 8 Index

Comments or enquiries should be made to Keith Hopper . Page last modified: Thursday, 25 May 2000. |