Hints for programming and running Algernon

  1. If-needed and If-added rules
  2. Accessing LISP from a rule
  3. Silent running
  4. Finding and tracing rules
  5. Suppressing rule continuations
  6. How to print frames
  7. Getting statistics about the Algernon KB

1) If-needed and If-added rules

Algernon has no rules about when to use an if-added (forward-chaining) rule versus an if-needed (backward-chaining) rule. However, some heuristics have developed over the years on the semantics of forward versus backward reasoning:

2) Accessing LISP from a rule

Use :BIND, :EVAL and :TEST to access LISP. The clauses containing:BIND and :EVAL always succeed (in the Algernon sense), but the clause containing :TEST will fail (in Algernon) if the LISP function returns NIL.

3) Silent running

The trace level determines how much output is generated by Algernon. Use the function (algy-trace level) to set the trace level. The normal trace level is 1. A trace level of 0 will suppress all Algernon messages. This is useful for initializing a KB. The macro silently is provided for this:
See the version 3 documentation for more information about tracing in Algernon.

4) Finding and tracing rules

Since rules are given arbitrary names, such as Rule24, it is sometimes difficult to find a rule after it has been defined. Two functions may help to find and debug rules:
  (find-rule key)

      if-added rules:  KEY is the first clause of the antecedent.
     if-needed rules:  KEY is the first clause of the consequent.

  Example:  (find-rule '(isa ?x physical-objects))  ==> RULE17
After finding a rule, you may wish to trace it:
  (algy-trace-rule rule-frame)
  (algy-untrace-rule rule-frame)


    (algy-trace-rule   'RULE17)
    (algy-untrace-rule 'RULE23)

5) Suppressing rule continuations

Rule continuations sometimes conflict with the desired flow of control in the system. Algernon provides two ways to suppress rule continuations (also called rule completions).

First, continuations can be suppressed on a per-clause basis when a rule is defined. In the example below, no rule continuations will be created for the third clause of the antecedent of the rule. (Continuations are never created for clauses in the consequent of a rule.)

  ((father  ?me  ?dad)
   (brother ?dad ?uncle)
   (:NO-CONTINUATION (sister ?uncle ?aunt))
   (aunt ?me ?aunt))

You may wish to suppress rule continuations for an entire rule. You may do this when the rule is defined by using the WITH-NO-CONTINUATIONS macro, as in the following example:

     (tell '((father  ?me  ?dad)
             (brother ?dad ?uncle)
             (sister ?uncle ?aunt)
             (aunt ?me ?aunt)))
Note that this must be done when the rule is defined, not when the rule is executed.

6) Printing Frames

The simplest way to print frames is to call the :SHOW operator in Algernon.
  (tell '((:show Mary)))
For more flexibility from LISP, you can call the following functions from the SFS module:
  SFS:KB-PRINT       frame &OPTIONAL stream
SFS stands for Simple Frame System, which is the module that stores Algernon frames and slots. If you call SFS:KB-PRINT, it will try to figure out what the object is (slot, frame, etc.) and call the appropriate function. If you know what you are printing, you can directly call an appropriate function such as SFS:KB-PRINT-FRAME.

6)Getting statistics about the Algernon KB

Use the function ALGY-STATS to count the number of frames and relations in the current KB.

[Algernon v3 home]

This page was created by

Micheal Hewett