24.11.2014 Views

flex Expert System Toolkit - LPIS

flex Expert System Toolkit - LPIS

flex Expert System Toolkit - LPIS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7. Knowledge Specification Language 96<br />

Constraints<br />

Demons<br />

<strong>flex</strong> toolkit<br />

A constraint is a validity check which can be attached to an attribute of a<br />

frame. It is automatically invoked whenever the value for that slot changes.<br />

The checks associated with a constraint are executed immediately before the<br />

value of the slot is to be changed, and the value only changes if this check<br />

succeeds. If the check fails then the slot is not updated, and the update itself<br />

will fail.<br />

Note that a demon may be used to perform checks after a slot value has<br />

changed.<br />

The general format of a constraint is as follows.<br />

constraint constraint_name<br />

when Attribute changes<br />

from Expression1<br />

to Expression2<br />

and condition1(s)<br />

then check that condition2(s)<br />

otherwise directive(s) .<br />

The from, to, the conditions1 and the otherwise are all optional.<br />

Example<br />

This example checks that a vessel is never filled to beyond its capacity. If<br />

the proposed value is invalid, an error message is written (the otherwise<br />

part of the constraint) and the slot update does not take place.<br />

constraint maximum_contents_of_vessel<br />

when the contents of Vessel changes to X<br />

and Vessel is some vessel<br />

then check that number( X )<br />

and X =< the Vessel `s capacity<br />

otherwise write( 'Illegal contents of vessel ' )<br />

and write( Vessel )<br />

and write( ' Contents ' )<br />

and write( X )<br />

and nl .<br />

This next example makes sure that the number of widgets in a<br />

container never falls below zero.<br />

constraint minimum_widgets<br />

when the widgets of Container changes to N<br />

and Container is some container<br />

then check that N > 0<br />

otherwise Container`s widgets becomes 0.<br />

A demon is a procedure which can be attached to an attribute of a frame. It

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

Saved successfully!

Ooh no, something went wrong!