24.11.2014 Views

flex Expert System Toolkit - LPIS

flex Expert System Toolkit - LPIS

flex Expert System Toolkit - LPIS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

7. Knowledge Specification Language 78<br />

The basic format of a repeat-until loop is:<br />

repeat directive(s)<br />

until condition(s)<br />

end repeat<br />

Example<br />

The following action repeatedly adds one to the current value of the up<br />

attribute of count and subtracts one from the current value of the down<br />

attribute of count until the up value is greater than or equal to the down<br />

value.<br />

action balance ;<br />

do repeat add 1 to the up of count<br />

and subtract 1 from the down of count<br />

until the up of count >= down of count<br />

end repeat<br />

and write( 'Balance ' )<br />

and write( up of count ) and tab( 1 )<br />

and write( down of count ) and nl .<br />

Note the use of the built-in Prolog predicates write/1, tab/1 and nl/0.<br />

Recall that the increment and decrement operators, add and subtract,<br />

only increment and decrement the current values of attributes. If there is no<br />

current value the directive subtract will fail. In the case of the add<br />

directive, if there is no current value the increment will be assigned to the<br />

current value of the slot.<br />

While-Do Loops<br />

While loops repeat the given directive while a condition holds. The directive<br />

is performed after the test is made. The basic format of a while-do loop is<br />

as follows.<br />

while condition(s)<br />

do directive(s)<br />

end while<br />

Example<br />

The following action would be used to remove from the customer loan<br />

records of a bank all instances of customer whose loan has been repaid.<br />

action remove_paid_customer ;<br />

do while Customer is some customer<br />

<strong>flex</strong> toolkit

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

Saved successfully!

Ooh no, something went wrong!