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.

4. Data-Driven Programming 45<br />

contents<br />

constraint<br />

check_contents<br />

jug1<br />

jug<br />

update slot<br />

contents of jug1<br />

test<br />

is updated contents<br />

less than capacity<br />

succeed<br />

allow update<br />

fail<br />

fail update<br />

actions<br />

write 'contents not<br />

updated'<br />

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

The code for this example could be written as follows:<br />

frame jug<br />

default contents are 0 and<br />

default capacity is 7 .<br />

instance jug1 is a jug .<br />

constraint check_contents<br />

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

and Jug is some jug<br />

then check that number( X )<br />

and X =< Jug`s capacity<br />

otherwise write( 'contents not updated' )<br />

and nl .<br />

Note the use of Jug, a local variable, which will unify with any frame or<br />

instance which has, in this case, a contents attribute.<br />

Attaching Demons to Slot Updates<br />

A demon is attached to an individual slot. It is activated whenever the<br />

current value of that slot is updated, and the activation occurs immediately<br />

after the update.<br />

A demon has two main parts:

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

Saved successfully!

Ooh no, something went wrong!