25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6. Expressions<br />

where bd is either a set bind or a type bind, and e is a boolean expression involving the<br />

pattern identifiers of bd. The iota operator can only be used if a unique value exists which<br />

matches the bind and makes the body expression e yield true (i.e. exists1 bd & e<br />

must be true). The semantics of the iota expression is such that it returns the unique value<br />

which satisfies the body expression (e).<br />

Examples: Using the values sc1,...,sc4 defined by<br />

✞<br />

✡✝<br />

sc1 = mk_Score (, 3, 0, 0, 9);<br />

sc2 = mk_Score (, 1, 1, 1, 4);<br />

sc3 = mk_Score (, 0, 2, 1, 2);<br />

sc4 = mk_Score (, 0, 1, 2, 1);<br />

✆<br />

we have<br />

iota x in set {sc1,sc2,sc3,sc4} & x.team = ≡ sc1<br />

iota x in set {sc1,sc2,sc3,sc4} & x.points > 3 ≡ ⊥<br />

iota x : Score & x.points < x.won ≡ ⊥<br />

Notice that the last example cannot be executed and that the last two expressions are undefined<br />

- in the former case because there is more than value satisfying the expression, and in<br />

the latter because no value satisfies the expression.<br />

6.7 Set Expressions<br />

Syntax: expression = . . .<br />

| set enumeration<br />

| set comprehension<br />

| set range expression<br />

| . . . ;<br />

set enumeration = ‘{’, [ expression list ], ‘}’ ;<br />

expression list = expression, { ‘,’, expression } ;<br />

set comprehension = ‘{’, expression, ‘|’, bind list,<br />

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

set range expression = ‘{’, expression, ‘,’, ‘...’, ‘,’,<br />

expression, ‘}’ ;<br />

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

✞<br />

{e1, e2, e3, ..., en}<br />

✡✝<br />

✆<br />

51

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

Saved successfully!

Ooh no, something went wrong!