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 13. Statements<br />
Examples: The operation in the previous example (Swap) illustrated normal assignment. The<br />
operation Win sd, a refinement of Win on page 91 illustrates the use of state designators to<br />
assign to a specific map key:<br />
✞<br />
✡✝<br />
Win_sd : Team * Team ==> ()<br />
Win_sd (wt,lt) ==<br />
let gp in set dom gps be st<br />
{wt,lt} subset {sc.team | sc in set gps(gp)}<br />
in<br />
gps(gp) := { 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 />
The operation SelectionSort is a state based version of the function selection sort<br />
on page 44. It demonstrates the use of state designators to modify the contents of a specific<br />
sequence index, using the <strong>VDM</strong>-SL state St or the <strong>VDM</strong>++ instance variables defined on<br />
page <strong>10</strong>1.<br />
✞<br />
functions<br />
min_index : seq1 of nat -> nat<br />
min_index(l) ==<br />
if len l = 1<br />
then 1<br />
else let mi = min_index(tl l)<br />
in if l(mi+1) < hd l<br />
then mi+1<br />
else 1<br />
operations<br />
SelectionSort : nat ==> ()<br />
SelectionSort (i) ==<br />
if i < len l<br />
then (dcl temp: nat;<br />
<strong>10</strong>3