We will create a rule newrule(X) :- w,x,y,z(X) .
The body of the rule is a tuple, a construction in the form of (w, x, y ...).
For different body lengths, starting without a body:
assert(goal). assert(goal:-cond). assert(goal:-(cond1,cond2)).
The tuple operator is a comma (`, '), as in', '(a, b) == (a, b).
%%%% %%%% Name: runtime.pl -- Runtime rule insertion. %%%% create_a_rule :- Cond=[w,x,y,z(X)], Head=newrule(X), list_to_tuple(Cond,Body), dynamic(Head), assert(Head :- Body), listing(Head). list_to_tuple([],_) :- ValidDomain='[x|xs]', Culprit='[]', Formal=domain_error(ValidDomain, Culprit), Context=context('list_to_tuple','Cannot create empty tuple!'), throw(error(Formal,Context)). list_to_tuple([X],X). list_to_tuple([H|T],(H,Rest_Tuple)) :- list_to_tuple(T,Rest_Tuple). :- create_a_rule. :- listing(newrule).
-
There are two lists. The first list from listing() is called in create_a_rule() . The second list from the listing() command on the last line of the source.
?- [runtime]. :- dynamic newrule/1. newrule(A) :- w, x, y, z(A). :- dynamic newrule/1. newrule(A) :- w, x, y, z(A). % runtime compiled 0.01 sec, 1,448 bytes true.