LYCOS RETRIEVER
Prolog: Rules
built 657 days ago
Prolog functors are translated to compiled Common Lisp functions. A single Lisp function combines all rules for each distinct functor/arity. Special treatment is given for facts, that is, rules with no variables in the head and no clauses in the body. The Lisp function automatically captures these as data instead of code. This allows reasonably large collections of data to be specified as regular Prolog rules. Larger, highly-scalable data sets can be implemented by extensions outlined below.
Source:
Prolog does not provide for a function type therefore, functions must be defined as relations. That is, both the arguments to the function and the result of the function must be parameters to the relation. This means that composition of two functions cannot be constructed. As an example, here is the factorial function defined as relation in Prolog. Note that the definition requires two rules, one for the base case and one for the inductive case.
Source:
Whenever Prolog sees the special symbol :-, Prolog creates a new pattern-matching rule. The basic meaning of :- is very simple: to match whatever is to left of the :-, the part to the right must be matched. This allows to "decompose" complex patterns into smaller, more manageable ones.
Source:
A Prolog functor/arity is compiled automatically the first time it is called. Any assert or retract to that functor/arity automatically invalidates the compiled function such that it will be recompiled the next time it is called. While the Allegro compiler is reasonably fast, performance may be poor if dynamic fact/rule management is performed using assert and retract with high bandwidth, interspersed with calls to the functor/arity. In such applications it would be better to use the
Source:
The arguments in a query are matched (or unified in Prolog terminology) to select the appropriate rule. Here is an example which makes extensive use of pattern matching. The rules for computing the derivatives of polynomial expressions can be written as Prolog rules. A given polynomial expression is matched against the first argument of the rule and the corresponding derivative is returned.
Source:
This may be called after new rules are asserted before making Prolog queries. Called with no arguments, it compiles all functors needing (re)compilation. Otherwise, a functor/arity will be compiled automatically the first time it is called.
Source: