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 13. Statements<br />

✞<br />

✡✝<br />

ResetStack();<br />

...<br />

top := PopStack();<br />

✆<br />

where PopStack could be defined as:<br />

✞<br />

✡✝<br />

PopStack: () ==> Elem<br />

PopStack() ==<br />

def res = hd stack in<br />

(stack := tl stack;<br />

return res)<br />

pre stack []<br />

post stack˜ = [RESULT] ˆ stack<br />

✆<br />

where stack is a global variable.<br />

In <strong>VDM</strong>++ and <strong>VDM</strong>-RT this Stack example can be made like:<br />

✞<br />

class Stack<br />

instance variables<br />

stack: seq of Elem := [];<br />

operations<br />

public Reset: () ==> ()<br />

Reset() ==<br />

stack := [];<br />

public Pop: () ==> Elem<br />

Pop() ==<br />

def res = hd stack in<br />

(stack := tl stack;<br />

return res)<br />

pre stack []<br />

post stack˜ = [RESULT] ˆ stack<br />

✡✝<br />

end Stack<br />

✆<br />

In the example the operation Reset does not have any parameters and does not return a<br />

113

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

Saved successfully!

Ooh no, something went wrong!