25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6. Expressions<br />

6.8 Sequence Expressions<br />

Syntax: expression = . . .<br />

| sequence enumeration<br />

| sequence comprehension<br />

| subsequence<br />

| . . . ;<br />

sequence enumeration = ‘[’, [ expression list ], ‘]’ ;<br />

sequence comprehension =<br />

‘[’, expression, ‘|’, set bind,<br />

[ ‘&’, expression ], ‘]’ ;<br />

subsequence = expression,<br />

‘(’, expression, ‘,’, ‘...’, ‘,’,<br />

expression, ‘)’ ;<br />

Semantics: A sequence enumeration has the form:<br />

✞<br />

[e1, e2, ..., en]<br />

✡✝<br />

✆<br />

where e1 through en are general expressions. It constructs a sequence of the enumerated<br />

elements. The empty sequence must be written as [].<br />

A sequence comprehension has the form:<br />

✞<br />

✡✝<br />

[e | pat in set S & P]<br />

where the expression e will use the identifiers from the pattern pat (normally this pattern<br />

will simply be an identifier, but the only real requirement is that exactly one pattern identifier<br />

must be present in the pattern). S is a set of values (normally natural numbers). The bindings<br />

of the pattern identifier must be to some kind of numeric values which then are used to<br />

indicate the ordering of the elements in the resulting sequence. It constructs a sequence by<br />

evaluating the expression e on all the bindings for which the predicate P evaluates to true.<br />

A subsequence of a sequence l is a sequence formed from consecutive elements of l; from<br />

index n1 up to and including index n2. It has the form:<br />

✞<br />

✡✝<br />

l(n1, ..., n2)<br />

where n1 and n2 are positive integer expressions. If the lower bound n1 is smaller than 1<br />

(the first index in a non-empty sequence) the subsequence expression will start from the first<br />

53<br />

✆<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!