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 />

Semantics: The self expression has the form:<br />

✞<br />

self<br />

✡✝<br />

✆<br />

The self expression returns a reference to the object currently being executed. It can be used<br />

to simplify the name space in chains of inheritance.<br />

Examples: Using the class Tree defined on page 28 we can specify a subclass called BST which<br />

stores data using the binary search tree approach. We can then specify an operation which<br />

performs a binary search tree insertion:<br />

✞<br />

Insert : int ==> ()<br />

Insert (x) ==<br />

(dcl curr_node : Tree := self;<br />

✡✝<br />

while not curr_node.isEmpty() do<br />

if curr_node.rootval() < x<br />

then curr_node := curr_node.rightBranch()<br />

else curr_node := curr_node.leftBranch();<br />

curr_node.addRoot(x);<br />

)<br />

✆<br />

This operation uses a self expression to find the root at which to being traversal prior to<br />

insertion. Further examples are given in section 13.9.<br />

6.15 The Threadid Expression (<strong>VDM</strong>++ and <strong>VDM</strong>-RT)<br />

Syntax: expression = . . .<br />

| threadid expression ;<br />

threadid expression = ‘threadid’ ;<br />

Semantics: The threadid expression has the form:<br />

✞<br />

threadid<br />

✡✝<br />

✆<br />

The threadid expression returns a natural number which uniquely identifies the thread in<br />

which the expression is executed. Note that periodic threads gets a new threadid at the start<br />

of each new period.<br />

60

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

Saved successfully!

Ooh no, something went wrong!