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 105<br />

Templates<br />

synonym weight_calc<br />

its volume times its density .<br />

All occurrences of weight_calc will be replaced by the term its<br />

volume times its density.<br />

synonym interest_rate 8.5 .<br />

All occurrences of interest_rate will be replaced by the number 8.5.<br />

Here, if the interest rate changes, only one change is necessary (to the<br />

synonym definition) before recompiling source code.<br />

Like a synonym, a template assists the readability of KSL statements. A<br />

template can be thought of as a parameterised synonym, allowing textual<br />

replacements at compile-time. The ^ symbol is used to indicate an argument<br />

position.<br />

A template may have a positive form and an optional negative form. The<br />

basic format of a template is:<br />

template replacement<br />

positive_template ;<br />

negative_template .<br />

At compile time, any terms of the form positive_template will be<br />

replaced by replacement, and any terms of the form<br />

negative_template will be replaced by not replacement, with<br />

arguments being replaced appropriately. Often the replacement term will<br />

be defined as a relation or an action.<br />

For example, suppose we have the following template (which only has a<br />

positive form).<br />

template empty_out<br />

empty out ^ .<br />

Then in KSL source code the expression<br />

empty out jug1<br />

will be converted at compile time to<br />

empty_out( jug1 )<br />

We may define the action empty_out/1, also making use of the template,<br />

as follows.<br />

action empty out X ;<br />

do X`s contents becomes 0 .<br />

<strong>flex</strong> toolkit

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

Saved successfully!

Ooh no, something went wrong!