Tabling Basics and List construction?

13 views
Skip to first unread message

Eleanor Todd

unread,
Apr 7, 2023, 10:27:05 AM4/7/23
to ErgoAI and XSB Users Forum
Hi folks,

Apologies for what are about to be pretty rudimentary questions.

First, here is a minimal test case:

office[contains->{desk,computer}].

%write_all_contents(?container) :-
write('Contents: ')@\io,
forall(?c)^(?container[contains->?c]~~>fmt_write('  %s', arg(?c))@\io),
nl@\io.


If I execute  the query %write_all_contents(office). I get:

Contents:   desk  computer

However, if I run it a second time in the same session, I get:

Contents:

It seems like the result of forall(?c)^(?container... is being tabled, and thus the write is only happening the first time. If that's the case, what is the syntax for keeping that predicate from being tabled? If that's not the case, what's going on here?

Second, in looking at alternate ways of achieving the above functionality, I thought I'd convert the results of office[contains->?C]. into a list. In swi-prolog I could do that using findall/3 but that function doesn't seem to be defined. How would I do that in ErgoAI?


Michael Kifer

unread,
Apr 7, 2023, 3:14:16 PM4/7/23
to ErgoAI-X...@coherentknowledge.com

regarding findall, you should look into aggregate functions like bag{...} and set{...}.


regarding the forall(....) statement, yes it translates into expressions that involves \naf, which is using a tabled predicate. Instead, I'd use

an approach similar to Prolog's - a fail loop:


office[contains->{desk,computer}].

%write_all_contents(?container) :-
        write('Contents: ')@\io,

        %write_data(?container).
%write_all_contents(?) :- nl@\io.


%write_data(?container) :-
        ?container[contains->?c],
        fmt_write('  %s', arg(?c))@\io,
        \false.
%write_data(?) :- \true.

?- %write_all_contents(office).

Another approach is to use abolish_all_tables in your version. This is more declarative, but uses a somewhat tricky op:


%write_all_contents2(?container) :-
        write('Contents2: ')@\io,


        forall(?c)^(?container[contains->?c]~~>fmt_write('  %s', arg(?c))@\io),

        nl@\io,
        abolish_all_tables@\plg.

?- %write_all_contents2(office).


In that case, make sure that no tabled pred/method depends on %write_all_contents2 (Ergo issues a warning in such cases anyway).

(I know, I should document   abolish_all_tables.)

--

       --- michael


 

--
You received this message because you are subscribed to the Google Groups "ErgoAI and XSB Users Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ErgoAI-XSB-for...@coherentknowledge.com.
To view this discussion on the web visit https://groups.google.com/a/coherentknowledge.com/d/msgid/ErgoAI-XSB-forum/a0db9d65-7ab5-4eb9-a7a8-52b776a1e5e2n%40coherentknowledge.com.

Eleanor Todd

unread,
Apr 7, 2023, 4:03:20 PM4/7/23
to Michael Kifer, ErgoAI-X...@coherentknowledge.com
Perfect, thank you!

Ironically, I had an earlier version working using a fail loop, but it didn't seem very Ergo-ish, so I tried to construct this more declarative version. :)

You received this message because you are subscribed to a topic in the Google Groups "ErgoAI and XSB Users Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/a/coherentknowledge.com/d/topic/ErgoAI-XSB-forum/lqIVjNjP5yE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ErgoAI-XSB-for...@coherentknowledge.com.
To view this discussion on the web visit https://groups.google.com/a/coherentknowledge.com/d/msgid/ErgoAI-XSB-forum/101cb636-c199-cc6f-6fc7-c3402f5decf0%40coherentknowledge.com.
Reply all
Reply to author
Forward
0 new messages