Skip to first unread message

Rangarajan Krishnamoorthy

unread,
Nov 20, 2018, 1:14:13 AM11/20/18
to ErgoAI, Flora-2, and XSB Users Forum
Hi,
Consider the following:

?- insert{${a[z -> zz]}@john}. // -(1)
?- ?x = john, insert{${a[z -> zz]}@?x}. // -(2)
?- ?x = john, ?fact =${a[g -> zz]}, insert{?fact@?x}. // - (3)

All three try to insert the same fact into the data base. (1) and (2) work as expected, but (3) results in the fact being inserted into the “main” module and instead of into “john”.

Why is this?

Regards,
Rangarajan

Michael Kifer

unread,
Nov 20, 2018, 1:58:49 AM11/20/18
to ErgoAI-Flor...@coherentknowledge.com

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


Michael Kifer

unread,
Nov 20, 2018, 11:20:28 PM11/20/18
to ErgoAI-Flor...@coherentknowledge.com

As a followup, suppose one wants to write a predicate that takes facts and inserts them into a specific module. Something like this won't work:
add_fact(?fact, ?module) :- insert{?fact@?module}.
because  a "fact" has a module baked in and tacking on it another @mod has no effect. One cannot insert a fact foo@bar into module moo because that fact is created for module bar, not moo.

One could try to take a fact in one module and create a similar fact in another module using the operation =.. but this is very clumsy (see how =.. decomposes different kinds of facts in the manual or just try interactively).
In a future release there might be a more straightforward way of replacing a module.

A better way of implementing the above add_fact predicate is to pass fact "templates" where the module is variable and not baked in. Eg, foo@?.  Here are the details:


%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.


Reply all
Reply to author
Forward
0 new messages