VDM-10 Language Manual
VDM-10 Language Manual
VDM-10 Language Manual
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 6. Expressions<br />
new expression = ‘new’, name, ‘(’, [ expression list ], ‘)’ ;<br />
Semantics: The new expression has the form:<br />
✞<br />
new classname(e1, e2, ..., en)<br />
✡✝<br />
✆<br />
An object can be created (also called instantiated) from its class description using a new<br />
expression. The effect of a new expression is that a ‘new’, unique object as described in class<br />
classname is created. The value of the new expression is a reference to the new object.<br />
If the new expression is invoked with no parameters, an object is created in which all instance<br />
variables take their “default” values (i.e. the values defined by their initialisation conditions).<br />
With parameters, the new expression represents a constructor (see Section 12.1) and creates<br />
customised instances (i.e. where the instance variables may take values which are different<br />
from their default values).<br />
Examples: Suppose we have a class called Queue and that default instances of Queue are empty.<br />
Suppose also that this class contains a constructor (which will also be called Queue) which<br />
takes a single parameter which is a list of values representing an arbitrary starting queue.<br />
Then we can create default instances of Queue in which the actual queue is empty using the<br />
expression<br />
✞<br />
✡✝<br />
new Queue()<br />
and an instance of Queue in which the actual queue is, say, e1, e2, e3 using the expression<br />
✞<br />
✡✝<br />
new Queue([e1, e2, e3])<br />
Using the class Tree defined on page 28 we create new Tree instances to construct nodes:<br />
✞<br />
mk_node(new Tree(), x, new Tree())<br />
✡✝<br />
✆<br />
✆<br />
✆<br />
6.14 The Self Expression (<strong>VDM</strong>++ and <strong>VDM</strong>-RT)<br />
Syntax: expression = . . .<br />
| self expression ;<br />
self expression = ‘self’ ;<br />
59