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

Calling a schema

Class member schemas that do not modify the current object are called using the normal dot-notation.

However, if the schema does modify the current object (i.e. it was declared with a "!" before the name), then the dot is replaced by an exclamation mark. This means that, at the point of call, you can tell that the object is changing. So, for example, given a variable myBook we can use the construct:

... myBook!publish(hardback@PublishedVersion) ...

to change the state of myBook such that it is recorded as available in paperback.

A schema call is a form of postcondition, so it may only appear where a postcondition is permitted. Apart from following the keyword post in a constructor or schema declaration, one other place you can use a postcondition is in an after expression. So if you have a value such as myFavoriteBook that you can't (or don't want to) change but you nevertheless wish were available in hardback, the expression:

... myFavoriteBook after it!publish(hardback@PublishedVersion) ...

yields a copy of myFavoriteBook with the versions attribute suitably amended. The keyword after can be preceded by any expression, so this:

... Book{"Alice in Wonderland", "Lewis Carroll"} after it!publish(hardback@PublishedVersion) ...

is equally valid. Note that the precedence of after is very low, so you frequently need to enclose after expressions in brackets.

Next:  Schemas that modify their parameters

 

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.