I assume that your definition of the object rules
is something like:
:- object(rules).
:- uses(user, [
cond/3, act/1
]).
:- public(add/2).
add(IF, THEN) :-
new_uid(U),
assertz(cond(IF, 0, U)),
assertz(act(U) :- THEN).
new_uid(1).
:- end_object.
This allows us to reproduce the results your report:
?- {rules}.
% [ /Users/pmoura/rules.lgt loaded ]
% (0 warnings)
true.
?- rules::add(greet(X),write([hi,X])).
true.
?- listing(cond/3).
:- dynamic cond/3.
cond(greet(_), 0, 1).
true.
?- listing(act/1).
:- dynamic act/1.
act(1) :-
write([hi, _]).
true.
The problem here is that you are asserting two separated clauses but clause variables are local to the clause.
A possible solution is to make that variable explicit. For example, by modifying your code to something like:
:- object(rules).
:- uses(user, [
cond/4, act/2
]).
:- public(add/3).
add(X, IF, THEN) :-
new_uid(U),
assertz(cond(X, IF, 0, U)),
assertz(act(X, U) :- THEN).
new_uid(1).
:- end_object.
You would then use queries such as:
?- rules::add(X, greet(X),write([hi,X])).
true.
?- listing(cond/4).
:- dynamic cond/4.
cond(A, greet(A), 0, 1).
true.
?- listing(act/2).
:- dynamic act/2.
act(A, 1) :-
write([hi, A]).
true.