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 4<br />
Algorithm Definitions<br />
In the <strong>VDM</strong> languages algorithms can be defined by both functions and operations. However,<br />
they do not directly correspond to functions in traditional programming languages. What separates<br />
functions from operations in the <strong>VDM</strong> languages is the use of local and global variables. Operations<br />
can manipulate both the global variables and any local variables. Both local and global<br />
variables will be described later. Functions are pure in the sense that they cannot access global<br />
variables and they are not allowed to define local variables. Thus, functions are purely applicative<br />
while operations are imperative.<br />
Functions and operations can be defined both explicitly (by means of an explicit algorithm definition)<br />
or implicitly (by means of a pre-condition and/or a post condition). An explicit algorithm<br />
definition for a function is called an expression while for an operation it is called a statement. A<br />
pre-condition is a truth-valued expression which specifies what must hold before the function/operation<br />
is evaluated. A pre-condition can only refer to parameter values and global variables (if<br />
it is an operation). A post-condition is also a truth valued expression which specifies what must<br />
hold after the function/operation is evaluated. A post-condition can refer to the result identifier,<br />
the parameter values, the current values of global variables and the old values of global variables.<br />
The old values of global variables are the values of the variables as they were before the operation<br />
was evaluated. Only operations can refer to the old values of global variables in a post-condition<br />
as functions are not allowed to change the global variables.<br />
However, in order to be able to execute both functions and operations by the interpreter they<br />
must be defined explicitly 1 . In the <strong>VDM</strong> langugaes it is also possible for explicit function and<br />
operation definitions to specify an additional pre- and a post-condition. In the post-condition of<br />
explicit function and operation definitions the result value must be referred to by the reserved word<br />
RESULT.<br />
1 Implicitly specified functions and operations cannot in general be executed because their post-condition does not need<br />
to directly relate the output to the input. Often it is done by specifying the properties the output must satisfy.<br />
33