Ordered
Chapter 4. Ordered and Scalar Types
4.1.1. ordered: type;
An ordered type is any type whose examples are partially or completely
ordered.
Commentary
As defined above, an ordered type is any type whose examples are
partially or completely ordered. The type ordered is the supertype of all
ordered types in Easel.
# STATUS: planned olives: type is enum(large, jumbo, gigantic, colossal); my_ints: type is 2..6; confirm olives << ordered; # olives are a subtype of type ordered confirm my_ints << ordered; # my_ints are a subtype of type ordered
Users can declare a new ordered type by defining a less-than operator 4.1. New types can be declared to inherit from ordered, but
unless the less-than operator is defined, the type cannot be used in relational
expressions.
# STATUS: planned cars: type is ordered; sedan: type is property cars; SUV: type is property cars; Honda: sedan := new car; Trooper: SUV := new car; if (Honda < Trooper) then null();# Error
Here the simple fact of declaring cars to be ordered does not define a
comparison operator, so that the if condition fails. Note however that in
reasoning about ordered types, the Easel system will assume that a less-than
operator exists even if it has not been defined.
The type ordered is used in the definition of enumerations and numbers.
Unless the less-than operator is defined, user-declared ordered types are not
very useful, as the above example shows.
Note also that any type for which the less-than operator has been defined
is a subtype of ordered, whether it is explicitly declared that way or not.
Equality is built in for all types, and the greater-than,
greater-than-or-equal-to, and less-than-or-equal-to relations are all derived
from the less-than relationship.
Any type whose examples are fully ordered is a scalar type. Scalar types
include enumerations (5.7.2),
machine integers (4.3.1),
numbers (5.1.1), integers, and real
numbers. Integers and real numbers are not supported. Complex numbers are not
scalars.
4.2.1. scalar: ordered type;
A scalar type is an ordered type whose values form a fully ordered
sequence.
Commentary
The soldiers example in 4.1.2
illustrates the difference between scalar and partially ordered types; here is
another example:
# STATUS: planned totally_ordered(i: int): scalar; partially_ordered(i: int): scalar; T3: totally_ordered := totally_ordered 3; T9: totally_ordered := totally_ordered 9; "<"(x: totally_ordered, y: totally_ordered): boolean is return (x.i < y.i); "<"(x: partially_ordered, y: partially_ordered): boolean is if (x.i < 1000 & y.i < 1000) then return true; else return ?; confirm T3 < T9;
Here the types totally_ordered and partially_ordered are identical
except for the fact that the less-than operator for partially_ordered is
undefined for values above 1000.
Machine integers are a built-in enumeration type for the integers in the
range -32768 .. 32767. Machine integers all have literals as defined in A.3 . Relational operations (see 4.1), enumeration operations (see 5.7) and the operations of this section apply to machine
integers. Machine integers may be used anywhere numbers are required. Numbers
that are integers in the range of machine integers may be used anywhere machine
integers are required. It is illegal to use any other number where an integer
is required. The bit by bit operations of Section 4.4 operate on integers.
Commentary
The following example illustrate the use of bit-wise operations. The
first two comment lines define the equivalence between two decimal and binary
numbers being used. The next line shows how pair-wise ANDing of the binary bit
strings of these two numbers results on the binary number 1000 (8 decimal).
# STATUS: current # 10 (decimal) = 1010 (binary) # 12 (decimal) = 1100 (binary) confirm band(10, 12) = 8; confirm bor(10, 12) = 14; confirm bxor(10, 12) = 6; confirm (bnot 10) = (-11); confirm bsr(10, 2) = 2; confirm bsc(10, 12) = 40960; confirm bsa(10, 2) = 2; confirm bsa((-10), 2) = (-3);
For more information, contact SEI Customer Relations, customer-relations@sei.cmu.edu
return to top
|
Easel Language Reference Manual and Users'
Guide
Easel main page