next up previous contents index
Next: Calling Lisp from Algernon Up: Special Forms Previous: Declaring Rules

Calling Algernon from Lisp

 

An Algernon knowledge-base can be regarded as the knowledge about the world possessed by an individual agent. Algernon interacts with the world through a tell/ask   (or equivalently, assert/query) interface by which we tell things to Algernon and ask questions of the knowledge-base.

tell path &key :retrieve :eval :collect :comment
     ask path &key :retrieve :eval :collect :comment

The functions tell and ask take an access path and assert or query it to the Algernon knowledge base. These operations may branch on multiple bindings while following the path. If the keyword :retrieve is t, only facts explicitly stored in the KB are retrieved, and no backward-chaining  rules are invoked. If no sets of bindings are found, the operation fails and nil is returned.

If the operation succeeds, then the Lisp forms provided for the :eval and :collect keywords are instantiated with values substituted for Algernon variables in each binding found. The :eval forms are evaluated, and the values of the :collect forms are collected and returned.  If no :collect form is provided, t is returned after a successful operation. The :comment string may be printed as trace output.

For example, if the brothers of Tom are Bob and Mike then:

	(ask '((brother Tom ?x)) :collect '?x)
will return: (Bob Mike). If further, Bob drives a Honda and Mike drives a Ford then:
	(ask '((brother Tom ?x) (drives ?x ?c))
	     :collect '(?x drives ?c))
will return:
	((Bob drives Honda)
	 (Mike drives Ford))

The a-assert  and a-query  functions are obsolete, but still supported. They call tell and ask, respectively, with trace output turned on.

a-assert string path
a-query string path

where string is a comment string, and path is an Algernon path (defined formally in section 2.1 above).



Micheal S. Hewett
Tue Oct 29 11:28:38 CST 1996