VDM-10 Language Manual
VDM-10 Language Manual
VDM-10 Language Manual
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 12. Operation Definitions<br />
specifiers can be found in section 14.4. Note that a static operation may not call non-static<br />
operations or functions, and self expressions cannot be used in the definition of a static<br />
operation.<br />
The following example of an explicit operation updates the <strong>VDM</strong>-SL state GroupPhase<br />
and the <strong>VDM</strong>++ instance variables of class GroupPhase when one team beats another.<br />
✞<br />
✡✝<br />
Win : Team * Team ==> ()<br />
Win (wt,lt) ==<br />
let gp in set dom gps be st<br />
{wt,lt} subset {sc.team | sc in set gps(gp)}<br />
in gps := gps ++ { gp |-><br />
{if sc.team = wt<br />
then mu(sc, won |-> sc.won + 1,<br />
points |-> sc.points + 3)<br />
elseif sc.team = lt<br />
then mu(sc, lost |-> sc.lost + 1)<br />
else sc<br />
| sc in set gps(gp)}}<br />
pre exists gp in set dom gps &<br />
{wt,lt} subset {sc.team | sc in set gps(gp)};<br />
✆<br />
An explicit operation consists of a statement (or several composed using a block statement),<br />
as described in section 13. The statement may access any state/instance variables it wishes,<br />
reading and writing to them as it sees fit.<br />
An implicit operation is specified using an optional pre-condition, and a mandatory postcondition.<br />
For example we could specify the Win operation implicitly:<br />
✞<br />
Win (wt,lt: Team)<br />
ext wr gps : map GroupName to set of Score<br />
pre exists gp in set dom gps &<br />
{wt,lt} subset {sc.team | sc in set gps(gp)}<br />
post exists gp in set dom} gps &<br />
{wt,lt} subset {sc.team | sc in set gps(gp)}<br />
and gps = gps˜ ++<br />
{ gp |-><br />
{if sc.team = wt<br />
then mu(sc, won |-> sc.won + 1,<br />
points |-> sc.points + 3)<br />
elseif sc.team = lt<br />
then mu(sc, lost |-> sc.lost + 1)<br />
else sc<br />
91