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.

<strong>VDM</strong>-<strong>10</strong> <strong>Language</strong> <strong>Manual</strong><br />

Quote expression<br />

pre Op1(1,mk St(2))<br />

post Op1(1,2,mk St(1), mk St(2))<br />

post Op2(2,mk St(1), mk St(2))<br />

post Op3(mk St(1), mk St(2))<br />

Explanation<br />

a bound to 1 in state St with n bound<br />

to 2<br />

a bound to 1, b bound to 2, state before<br />

with n bound to 1, state after with n<br />

bound to 2<br />

b bound to 2, state before with n bound<br />

to 1, state after with n bound to 2<br />

state before with n bound to 1, state after<br />

with n bound to 2<br />

For module B we can quote the pre and post conditions defined in this specification as<br />

illustrated below<br />

Quote expression<br />

Explanation<br />

pre Op1(1) a bound to 1<br />

post Op1(1,2) a bound to 1, b bound to 2<br />

post Op2(2) b bound to 2<br />

post Op3()<br />

No binding at all<br />

The exceptions clause can be used to describe how an operation should deal with error situations.<br />

The rationale for having the exception clause is to give the user the ability to separate<br />

the exceptional cases from the normal cases. The specification using exceptions does not<br />

give any commitment as to how exceptions are to be signalled, but it gives the means to<br />

show under which circumstances an error situation can occur and what the consequences are<br />

for the result of calling the operation.<br />

The exception clause has the form:<br />

✞<br />

errs COND1: c1 -> r1<br />

...<br />

CONDn: cn -> rn<br />

✡✝<br />

The condition names COND1, . . . , CONDn are identifiers which describe the kind of error<br />

which can be raised 2 . The condition expressions c1, . . . , cn can be considered as preconditions<br />

for the different kinds of errors. Thus, in these expressions the identifiers from<br />

the arguments list and the variables from the externals list can be used (they have the same<br />

scope as the pre-condition). The result expressions r1, . . . , rn can correspondingly be<br />

considered as post-conditions for the different kinds of errors. In these expressions the result<br />

identifier and old values of global variables (which can be written to) can also be used. Thus,<br />

the scope corresponds to the scope of the post-condition.<br />

Superficially there appears to be some redundancy between exceptions and pre-conditions<br />

2 Notice that these names are purely of mnemonic value, i.e. semantically they are not important.<br />

✆<br />

94

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

Saved successfully!

Ooh no, something went wrong!