# Section 8.16.1.3:
$STRING

This page contains the definition of the two generic $STRING abstract classes.

###### abstract class $STRING{ELT < $IS_EQ} < $STRINGS

#### Formal Definitions

This abstract class defines a state component which is a set of all instantiations of objects of any class sub-typing from this class in addition to the vdm model types used wherever this class name is used. Note that SAME has to be an instantiated class, not an abstract one.

types
SAME = object_type ;
$STRING_ELT = set of object_type
state
multi : $STRING_ELT
inv multi_types ==
forall obj in set multi_types & sub_type($STRING_ELT,obj)

NOTE | See the important note about vdm state in the notes on vdm-sl usage in this specification.

This abstract class characterises the concept of all forms of simple string whether binary, text or other as sequences of the argument class (elements) which must sub-type from $IS_EQ. Classes which sub-type from this shall have immutable semantics!

This class defines NO features of its own.

###### abstract class $STRING{ELT < $IS_EQ, FSTP < $FSTRING{ELT},
STP < $STRING{ELT}} < $STRING{ELT}, $SEARCH{ELT}, $BINARY

#### Formal Definitions

This abstract class defines a state component which is a set of all instantiations of objects of any class sub-typing from this class in addition to the vdm model types used wherever this class name is used. Note that SAME has to be an instantiated class, not an abstract one.

types
SAME = object_type ;
$STRING_ELT_FTP_STP = set of object_type
state
multi : $STRING_ELT_FTP_STP
inv multi_types ==
forall obj in set multi_types & sub_type($STRING_ELT_FTP_STP,obj)

NOTE | See the important note about vdm state in the notes on vdm-sl usage in this specification.

This abstract class characterises the concept of simple non-text strings as sequences of the argument class (elements) which must sub-type from $IS_EQ. The second and third class arguments are the 'corresponding' mutable ($FSTRINGS{ELT}) and immutable (sub-typing from this abstract class) string classes. Classes which sub-type from this class shall have immutable semantics!

#### plus

This is the first version of the string append operation which appends another string of the same kind to self and returns the result.

plus | (
| vals : SAME
| ) : SAME

##### Formal Signature

plus(self : SAME, vals : SAME) res : SAME

##### Pre-condition

pre len vals > 0

##### Post-condition

post res = self ^ vals

This feature returns a new string formed by appending the contents of other to the contents of self.

#### plus

This version of the string append operation a single element to self and returns the result.

plus | (
| val : ELT
| ) : SAME

##### Formal Signature

plus2(self : SAME, val : ELT) res : SAME

##### Pre-condition

pre true

##### Post-condition

post res = self ^ [val]

This feature returns a new string formed by appending the single element given to the contents of self.

#### plus

This version of the string append operation takes a mutable string as argument.

plus | (
| vals : FSTP
| ) : SAME

##### Formal Signature

plus3(self : SAME, vals : FSTP) res : SAME

##### Pre-condition

pre true

##### Post-condition

post res = self ^ vals

This feature returns a new string formed by appending the contents of the mutable string to the contents of self.

#### reverse

reverse | : SAME

##### Formal Signature

reverse(self : SAME) res : SAME

##### Pre-condition

Since the domain of the result is identical to the domain of self, the pre-condition is vacuously true.

##### Post-condition

pos forall idx in set inds self &
res(idx) = self(len self - idx + 1)

This routine returns a new string which has the same contents as self with all elements in the reverse order.

#### elt!

This iter version and the one following complement the one inherited by this abstraction. This permits the first element yielded to be the element indexed by the start argument.

elt! | (
once | start : CARD
| ) : ELT

##### Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

elt_iter2(self : SAME, start : CARD) res : ELT

##### Pre-condition

Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.

##### Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).

post history = history~ ^ [res]
and res = self(len history + start)

##### Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : (len history + start) = len self -> quit

This iter yields the elements of self in order beginning with the element at the given starting index.

#### elt!

This iter version specifies both the element to yield first and the number of elements to be yielded.

elt! | (
once | start : CARD
once | num : CARD
| ) : ELT

##### Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

elt_iter3(self : SAME, start : CARD, num : CARD) res : ELT

##### Pre-condition

Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.

##### Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).

post history = history~ ^ [res]
and res = self(len history + start)

##### Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : (len history = num)
or (len history + start) = len self -> quit

This iter yields num elements of self in order beginning with the element at the given starting index.

#### chunk!

This iter yields provides a substring sequence facility, the lengths of each dependent on the argument at each invocation. Note that the last iteration before quitting will yield the sub-sequence of the size indicated or the remainder of the string, whichever is the shortest sequence.

chunk! | (
| chunk_size : CARD
| ) : SAME

##### Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

chunk_iter(self : SAME, chunk_size : CARD) res : SAME

##### Pre-condition

Since the iter may quit when all elements have been yielded, the pre-condition is vacuously true.

##### Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes). Note also that the vdm sub-sequence operation yields a sub-sequence which is no longer than the range indicated if that would extend beyond the end of the sequence.

post history = history~ ^ res
and res = self((len history~ + 1), ..., (len history~ + chunk_size))

##### Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : (len history = len self -> quit

This iter yields in sequence successive sub-sequences of self the length of each being determined by the argument.

#### chunk!

This iter yields the character encodings of self in sequence starting at the one indicated.

chunk! | (
once | start : CARD,
| chunk_size : CARD
| ) : SAME

##### Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

chunk_iter2(self : SAME, start : CARD, chunk_size : CARD) res : SAME

##### Pre-condition

Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.

##### Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes). Note also that the vdm sub-sequence operation yields a sub-sequence which is no longer than the range indicated if that would extend beyond the end of the sequence.

post history = history~ ^ res
and res = self((start + len history~ + 1), ..., (start + len history~ + chunk_size))

##### Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : (len history + start) = len self -> quit

This iter yields successive sub-sequences of elements of self, starting the first sub-sequence at the given index.

| Language Index |  | Library Index |  | String Index

Comments or enquiries should be made to Keith Hopper. Page last modified: Monday, 26 February 2001. |