Sather Home Page

Section 8.11.2.1
BOOL

immutable class BOOL < $IS_EQ, $IMMUTABLE, $ANCHORED_FMT

Inheritance map $IS_EQ $IMMUTABLE $OPTION $STR $BINARY $FMT $ANCHORED_FMT

Formal Types

types

SAME = BOOL ;
BOOL = bool ;

This class provides the functionality of the basic Boolean logic domain. BOOL objects represent boolean values and either have the value `true' or the value `false'. The pervasive class BOOL bool defines only the three fundamental operations and, or and not. This library class defines several additional operators and conversion routines.

External specifications

The following feature is required to be implemented for this class in accordance with the specification given in $IS_EQ :-


The following features are required to be implemented for this class in accordance with the specification given by inheritance in $INSTR of which $ANCHORED_FMT is a sub-type :-


The following features are required to be implemented for this class in accordance with the specifications given by inheritance in $STR of which $ANCHORED_FMT and $IMMUTABLE are both sub-types :-


The following features are required to be implemented for this class in accordance with the specifications given by inheritance in $ANCHORED_FMT :-


The following features are required to be implemented for this class in accordance with the specifications given in $BINARY of which $IMMUTABLE is a sub-type :-


create

This feature provides a mechanism for creating a truth value from an octet. An implementation is free to use any bit-pattern to represent the truth value, provided that it is the identical bit-pattern to that produced when the binstr feature is applied (producing a single element binary string).

create (
val : OCTET
) : SAME
Formal Signature
create1(val : OCTET) res : SAME
Pre-condition

Note that the selector applied to the binstr operation result is accessing the first (and only) component.

pre val = binstr(res)(1)
Post-condition
post card(res) = OCTET.card(val)

This routine returns the truth value corresponding to the bit-pattern in the argument val.


create

This final variant of the create operation creates a truth value from the encoding of a string representation in the executing environment repertoire and encoding. The 'word' to be converted is expected to be in the language of the local culture.

create (
str : STR
) : SAME
Formal Signature
create3(bool_str : STR) res : SAME
Pre-condition
pre is_bool(str)
Post-condition

The string method is_prefix is defined in the class STR.

post STR.is_prefix(str(res),bool_str)

This routine returns the truth value corresponding to the text string argument. The actual characters required (and their encoding) are determined by the current cultural environment.

NOTE The internationally defined default characters for 'true' and 'false' are the digits '1' and '0' respectively in the local encoding. Most cultures will define pairs of values such as 'True/False' in English speaking cultures, 'Wahr/Falsch' in German speaking cultures, etc.

not

This feature provides the standard Boolean inversion operation.

not : SAME
Formal Signature

The name of the formal operation corresponding to 'not' has been modified since the word 'not' is a keyword in vdm-sl.

not_v(self : SAME) res : SAME
Post-condition
post res = not self

This feature returns the logical complement of self.


and

This feature provides the Boolean conjunction operation.

and (
other : SAME
) : SAME
Formal Signature

The name of the formal operation corresponding to 'and' has been modified since the word 'and' is a keyword in vdm-sl.

and_v(self : SAME, other : SAME) res : SAME
Post-condition
res = (self
and other)

This routine returns true if and only if self and other are both true, otherwise false.


or (
other : SAME
) : SAME

Formal Signature

or(self : SAME, other : SAME) res : SAME

Post-condition

res = (self

or other)

This routine returns true if and only if either self or other or both are true, otherwise false.


is_eq

This feature provides the logical equality operation for Boolean values. It may be used in infix logical expressions.

is_eq (
other : SAME
) : SAME
Formal Signature
is_eq(self : SAME, other : SAME) res : SAME
Post-condition
post res = (self
= other)

This routine returns true if and only if both self and other have the same value, otherwise false.


is_eq

This feature provides the logical equality operation for a logical value which may be 'hidden' in an abstract type and self. It may be used in infix logical expressions. Note, however, that object equality will be used if the argument is not of this type.

is_eq (
other : $OB
) : SAME
Formal Signature

The formal argument type is 'any object type', but an actual argument must, of course, be an instantiated object.

is_eq2(self : SAME, other : $OB) res : SAME
Post-condition
post res = (self = other)

This routine returns true if and only if both self and other have the same value, otherwise false. This version is provided for use where some abstract type object happens to derive from $IS_EQ. True can only be returned if the actual object is of this type.


is_bool

This feature returns a validity indicator if the string contained in the argument is a valid representation of either the value true or the value false. If empty then the corresponding indication is given, otherwise an out of range indication. The string does not have to be a complete 'word', rather it must be at least as long as needed to differentiate the two values - thus, in English where "True" and "False" are the two values, then the first character alone is all that is needed. If the rest of the word is there and does not correspond to 'rue' or 'alse' then, of course, out of range is returned.

is_bool (
str : STR
) : CONVERSION_RESULTS
Formal Signature
is_bool(str : STR) res : CONVERSION_RESULTS
Post-condition
post (res = All_Right
and (STR.is_prefix(str(true))
or STR.is_prefix(str(false))))
or (res = Empty
and STR.asize(str) = 0)
or (res = Out_of_Range)

This routine returns All_Right if str is a valid text representation of a truth value, Empty if the string was empty and Out_of_Range for any other string content.


xor

This is the first of those routines provided to complete the possible binary operations in the logical domain. They all have their usual mathematical meaning.

xor (
other : SAME
) : SAME
Formal Signature
xor(self : SAME, other : SAME) res : SAME
Post-condition
post res = ((self
and not other)
or (other
and not self))

This routine returns true if and only if only one of self and other is true, otherwise false. It is identical to a not equal predicate.


xnor

xnor (
other : SAME
) : SAME
Formal Signature
xnor(self : SAME, other : SAME) res : SAME
Post-condition
post res = ((self
and other)
or (not other
and not self))

This routine returns true if and only if self and other have the same logical value. It is identical to the is_eq predicate.


nand

nand (
other : SAME
) : SAME
Formal Signature
nand(self : SAME, other : SAME) res : SAME
Post-condition
post res = not (self
and other)

This routine returns the logical complement of the result of anding self and other.


nor

nor (
other : SAME
) : SAME
Formal Signature
nor(self : SAME, other : SAME) res : SAME
Post-condition
post res = not (self
or other)

This routine returns the logical complement of the result of oring self and other.



implies

implies (
other : SAME
) : SAME
Formal Signature
implies(self : SAME, other : SAME) res : SAME
Post-condition
post res = (not self
or other)

This routine returns if and only if self implies other. It is the same operation as nand_not.


and_rout

This routine is identical to the and operation built in to the language. It is provided for possible use as a bound routine.

and_rout (
other : SAME
) : SAME
Formal Signature
and_rout(self : SAME, other : SAME) res : SAME
Post-condition
post res = (self
and other)

This routine is the same as the and operation useful when making bound routines.


or_rout

This routine also corresponds to a built-in operator - or. It is provided for possible use as a bound routine.

or_rout (
other : SAME
) : SAME
Formal Signature
or_rout(self : SAME, other : SAME) res : SAME
Post-condition
post res = (self
or other)

This routine is the same as the or operation - provided for use when making bound routines.


and_not

and_not (
other : SAME
) : SAME
Formal Signature
and_not(self : SAME, other : SAME) res : SAME
Post-condition
post res = (self
and not other)

This routine returns the result of self and the complement of other.


or_not

or_not (
other : SAME
) : SAME
Formal Signature
or_not(self : SAME, other : SAME) res : SAME
Post-condition
post res = (self or not other)

This routine returns the result of self or the complement of other.


nand_not

nand_not (
other : SAME
) : SAME
Formal Signature
nand_not(self : SAME, other : SAME) res : SAME
Post-condition
post res = not (self and not other)

This routine returns the result of self nanded with the complement of other. It is the same as the complement of self or other.


nor_not

nor_not (
other : SAME
) : SAME
Formal Signature
nor_not(self : SAME, other : SAME) res : SAME
Post-condition
post res = not (self and other)

This routine returns the result of self nored with the complement of other. It is the same as the complement of self and other.


card

This operation is provided solely for backward compatibility with earlier versions of the library. It returns the value 1 when self is true and the value zero otherwise.

card : CARD
Formal Signature
card(self : SAME) res : CARD
Post-condition
post (self and (res = 1))
or (not self and (res = 0))

This routine returns the value 1 if self is true, otherwise the value zero.



Language Index Library Index Non-numeric Index
Comments or enquiries should be made to Keith Hopper.
Page last modified: Wednesday, 22 November 2000.
Produced with Amaya