Facts - summary and procedures


The database is held as list called "facts. Each element of :facts is itself a list which you can take to represent an individual fact or assertion.

The contents of :facts can be displayed at any time by using the primitive print - by typing pr :facts. If you would rather see the current set of facts as a vertical list, then get hold of vprint from the Toolbox and use vprint :facts.

Otherwise, as far as the top-level user is concerned, there are four system specific commands:

Cleanup takes no input. It simply clears out any pre-existing facts from the database. (I.e. It sets up :facts as an empty list.)

Each of the other three commands takes one list as input. These lists may be of any length.

Learn adds a list representing a fact to the database. I.e. it puts the new fact at the head of (in the first position of) :facts. It will not allow duplication of a fact already in the database.

Forget removes a list representing a fact or tells you if no such fact is recorded anyway.

Query is the interrogation command, accepting a list representing 'question' as input.

Question formats

The input to query may take the form of a simple fact. In this case it provides the equivalent of a yes/no question. It is used for verification - or otherwise - of the fact. query [john likes mary] is equivalent to Is it a (known) fact that John likes Mary?

The input to query may also be a list containing occurrences of ? - a question mark used as a wild-card. The wild-card takes the place of the English question words what, where etc. in wh-questions. Unlike normal English question words, however, it is only used in positions in the input list where a corresponding full word is expected to be found in a database fact. [? is red] would, in other words, be used to elicit a response containing [roses is blue] and [blood is red], while [blood is ?] would be used to get the reply [blood is red] (always assuming such facts were in the database).

Notice that a ? substitutes for a single word and not a phrase (although Things to do with the Facts database suggests removing this restriction.) But notice also that it is possible with the wild-card to ask questions which would not be possible using English question words. [? ? ?], for example, could be used to retrieve any three word fact.

The procedures

The listing does not include the definition of remove (see the toolbox version) which is necessary to make the whole system work.

Beware of copying and pasting from this page. Run-on lines are represented here by indentation. A ready to run version is available.

to cleanup
make "facts []

to learn :fact
if member? :fact :facts [pr [I know that already] stop]
make "facts fput :fact :facts
( pr [O.K.] :fact )

to forget :fact
if not member? :fact :facts  
           [pr [I didn't know that anyway] stop]
make "facts remove :fact :facts
( pr [O.K.] :fact [is forgotten] )

to query :question
pr check :question :facts

to check :question :data
if empty? :data [op []]
if match? :question first :data 
          [op fput first :data check :question bf :data]
 op check :question bf :data
 to match? :this :that
 if and ( empty? :this ) ( empty? :that ) 
          [op "true]
 if or ( first :this ) = ( first :that ) ( first :this ) = "? 
          [op match? bf :this bf :that][op "false]


There are many ways in which this simple system can be developed. Here are some suggestions.

Ron Brasington
Department of Linguistic Science
The University of Reading

E-mail: ron.brasington@rdg.ac.uk