Ex 9 Comparing attributes of different types

This forum is for discussing the development of Rel examples and sample applications.
Chris Walton
Posts:76
Joined:Sat Aug 18, 2012 2:13 pm
Ex 9 Comparing attributes of different types

Post by Chris Walton » Sun Aug 18, 2013 9:10 pm

Comparing attributes of different types

Code: Select all

VAR Type_predicate BASE RELATION { 
  name CHARACTER, 
  predicate CHARACTER } 
  KEY { name };

OPERATOR TREAT_AS_CHARACTER(P ID ) RETURNS CHARACTER ;
  return THE_VALUE(P ) ;
END OPERATOR ;

CONSTRAINT Type_predicate_opt 
 (EXTEND Type_predicate :
  )Name := TREAT_AS_CHARACTER(name )} ){Name} 
  <= sys.Types{Name} ;
Note:
While Tutorial D/Rel abjure the use of type coercion, there are times, when dealing with text, it is useful to have a light weight mechanism to compare attributes of different types. The sort of problem this addresses is case sensitivity(or lack of it), different interpretations of naming conventions, and different styles of code writing. This example provides such a mechanism, but in a controlled, and hence type safe manner. It requires the definition of a specific conversion operator; and the comparison of two relvars, at least one of which will have been extended.

Post Reply