The main Lisp interface to Algernon consists of two functions a-assert and a-query .
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).
Two macros are provided to temporarily suppress Algernon output.
quietly &rest forms
silently &rest forms
Both macros evaluate their arguments as Lisp forms. silently suppresses all Algernon output, while quietly suppresses output unless an operation fails.
Algernon also provides an ask/tell interface designed for accessing the knowledge-base from Lisp:
tell path &key comment
ask path &key comment collect execute retrieve
These functions assert or query (respectively) the given path. In each case the comment is optional and is only used to label the operation.
tell produces no output unless the assertion fails, and returns t iff the assertion succeeds.
If retrieve is t then ask retrieves the path (thus suppressing the application of backward chaining rules ). If an execute form is given to ask, it is instantiated and executed once for each set of bindings produced by querying the path. ask produces no output. Its returned value is controlled by collect. If collect is nil (the default) then ask returns t iff the query of the path succeeds. Otherwise, ask returns the list formed by instantiating the collect form once for each set of bindings produced by the query (duplicate entries are suppressed). For example, if the brothers of Tom are Bob and Mike then:
(ask '((brother Tom ?x)) :collect '?x)should 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))should return:
((Bob drives Honda) (Mike drives Ford))