# 12.5 Facts

 Content

With structures, variables , and unification in place, you might think that the next logical step is to collect groups of structures and then to unify a variable structure with each one. However, logic programming introduces notions that veer from this course. The first notion is that a structure can represent a statement of truth, or what logic programming calls an axiom . For example, you can regard

` city(denver, 5280) `

as a model of the true statement that Denver's elevation is about 5,280 feet. A structure that contains no variables is a fact, which is one type of axiom. The other type of axiom is a rule, which you will meet shortly. In the classes in package sjm.engine , class Fact is a subclass of Structure , as Figure 12.2 shows.

##### Figure 12.2. The Fact class. A Fact object is a Structure object that contains no variables. If a fact has terms at all, they must be other facts.

The constructors for the Fact class that accept objects as terms wrap these objects as other facts. A Fact object is always a composition of facts. In other words, a structure that contains only data is a composition of structures that contain only data.The variety of constructors provided by the Fact class makes it easier to create new Fact objects. For example, you can create city facts as follows :

` package sjm.examples.engine;  import sjm.engine.*; /**  * This class shows the construction of a couple of facts.  */ public class ShowFacts { public static void main(String[] args) {     Fact d = new Fact(         "city",         new Fact[]{             new Fact("denver"),             new Fact(new Integer(5280))});     Fact j = new Fact(         "city", "jacksonville", new Integer(8));     System.out.println(d + "\n" + j); } } `

This prints

` city(denver, 5280)  city(jacksonville, 8) `

You can build a logic program from facts because facts are axioms.

 Top

Building Parsers With Javaв„ў
ISBN: 0201719622
EAN: 2147483647
Year: 2000
Pages: 169

Similar book on Amazon