Perfect Developer basic tutorial 6 This page last modified 2011-10-31 (JAC)

Postconditions

You've seen how we use postconditions to define the objects created by constructors, to define the changes made by a schema, and in after expressions to express the value that some expression would have if we made some changes to it. It's now time to cover postconditions in detail.

In Perfect, every postcondition precisely defines two things:

The most basic form of postcondition allows you to specify these two elements separately, like this:

change frame satisfy condition

for example:

change x, array[i] satisfy x' = array[i] & array'[i] = x

expresses that the values x and array[i] are swapped and nothing else changes. In the condition, we use a prime to denote the final value of a variable (unprimed variables refer to the initial value). For each variable in the change list, that variable (or some variable containing it) must occur primed at least once in the satisfy expression.

switched-on lamp Incidentally, array[i]' means exactly the same as array'[i] and so does self '.array[i] if array is an attribute of the current class.

It's very common to want to change a single variable by making its value equal to some expression; so we have a shorthand for this form. Specifically, any postcondition of the form:

change var satisfy var' = expr

can be abbreviated:

var! = expr

which is the sort of postcondition we've mainly used so far. Note that if you would need to bracket expr in the expression var' = (expr) - such as when expr is a forall, exists, for...yield or after expression, or expr contains a Boolean operator - then you also need to bracket expr in the postcondition var! = (expr).

A variation of the above is the postcondition

change var satisfy var' = var operator expr

where operator is any binary operator. This may be abbreviated to:

var! operator expr

So the postcondition

change array[index] satisfy array'[index] = array[index] + count

may be abbreviated to either

array[index]! = array[index] + count

or to

array[index]! + count

Next:  More postconditions

 

Save My Place Glossary Language Reference Manual
Tutorials Overview Main site   
Copyright © 1997-2012 Escher Technologies Limited. All rights reserved. Information is subject to change without notice.