Because ?fact is bound to a formula in the current module, which is apparently main in your case.
But ((foo@bar)@moo)@goo == foo@bar.
In contrast, in (1) and (2), insert{${foo}@john} == insert{${foo@john}} == insert{foo@john}.
Btw, you don't need reification in update ops, as they already
expect facts and rules.
--
--- michael
add_fact(?fact, ?module) :- insert{?fact@?module}.
%add_fact(?factTempl, ?module) :- ?factTempl ~ ?@?module,
insert{?factTempl}. // ~ is a meta-unification operator; ?module gets unified with the variable module in ?factTempl
?-newmodule{foobar}. // create a desired module
?- ?factTemplate = ${a[b->c]@?},
%add_fact(?factTemplate,foobar). // do the insertion for one specific fact template
?- a[b->?c]@foobar, writeln(test=?c)@\io. // test, if indeed inserted into the right module
Results:
?factTemplate = ${a[b->c]@foobar}
1 solution(s) in 0.001 seconds; elapsed time = 0.001
Yes
test = c
?c = c
1 solution(s) in 0.001 seconds; elapsed time = 0.001
Yes
Btw, the above uses %add_fact and not add_fact because it depends on an action (insert), so we use a transactional predicate here.