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

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

to slots or modify the facts / exceptions in the database.<br />

Its use is similar to a data statement in establishing the initial state of some<br />

problem, but, unlike data, anything executed by a do statement in this way<br />

is not re-established by the <strong>flex</strong> routine restart/1. A do statement is for<br />

executing directives once at compile time, and once only.<br />

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

do directive(s) .<br />

Examples<br />

do the contents of jugA become 2<br />

and jugB`s contents become jugB`s capacity - 2<br />

and remember that danger_level( yellow ) .<br />

do c1 is a new car whose engine_size is 1100<br />

and c1`s model := 'Whizzo'<br />

and c1`s colour := metallic_blue .<br />

To illustrate the difference between do and data, consider the following<br />

example.<br />

frame widget<br />

default screws is 0 and<br />

default bolts is 0.<br />

relation get_widget( W, S, B )<br />

if W is some widget<br />

whose screws is S and whose bolts is B.<br />

do w1 is a new widget<br />

whose screws is 50 and whose bolts is 10.<br />

data new_widgets<br />

do w2 is a new widget<br />

whose screws is 20 and whose bolts is 30.<br />

We may find the current instances of widget using the query<br />

get_widget/3. Initially after compilation, there will be two widgets, w1<br />

and w2, as declared by the data and do statements above.<br />

?- get_widget( W, S, B ).<br />

W = w1, S = 50, B = 10<br />

W = w2, S = 20, B = 30<br />

However, if we precede the query with the <strong>flex</strong> call to restart/0, which<br />

reinitialises the <strong>flex</strong> workspace, we will see that the widget w2 is restored (as<br />

in the data statement) but the widget w1 is not restored (because it was only<br />

declared in a do statement).<br />

?- restart, get_widget( W, S, B ).<br />

W = w2, S = 20, B = 30

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

Saved successfully!

Ooh no, something went wrong!