Simple question - XSB Prolog
I'm diving into the world of prolog headfirst but I seem to have hit shallow water!
I'm looking开发者_如何学Go at database manipulation in prolog with regards to this tutorial:Learn Prolog Now!
It states that I can see my database by entering listing
So i tried it and it should basically output everything in my .P file(facts, rules), but this is what i get, here are my sequence of commands:
? consult('D:\Prolog\testfile.P').
[testfile.P loaded]
? listing.
library_directory(C:blahblahpathtoXSB)
library_directory(C:blahblahXSBpath)
{this is listed around 5 times)}
shouldn't this command display what is in testfile.P, according to the tutorial?
also, after consult testfile.P i should be ableto use assert
to add more facts but it doesnt actually change anything in the testfile.P..?
any ideas
The behavior of the listing predicate varies by Prolog interpreter. The XSB documentation explains what code will be included in the output of listing/0:
Note that listing/0 does not list any compiled predicates unless they have the dynamic property (see predicate property/2). A predicate gets the dynamic property when it is explicitly declared as dynamic, or automatically acquires it when some clauses for that predicate are asserted in the database.
With a very simple test.P file containing this:
test(a,b).
Here is using listing/0 in XSB with both the consulted file and an asserted rule. It only outputs the dynamically asserted rule, not the contents of the file:
| ?- consult('test.P').
[test loaded]
yes
| ?- listing.
library_directory(/home/jeffd/xsb/XSB/packages).
library_directory(/home/jeffd/xsb/XSB/site/lib).
library_directory(/home/jeffd/xsb/XSB/site/config/i686-pc-linux-gnu/lib).
library_directory(/home/jeffd/xsb/XSB/config/i686-pc-linux-gnu/lib).
library_directory(/home/jeffd/.xsb/config/i686-pc-linux-gnu).
yes
| ?- assert(testing(c,d)).
yes
| ?- listing.
testing(c,d).
library_directory(/home/jeffd/xsb/XSB/packages).
library_directory(/home/jeffd/xsb/XSB/site/lib).
library_directory(/home/jeffd/xsb/XSB/site/config/i686-pc-linux-gnu/lib).
library_directory(/home/jeffd/xsb/XSB/config/i686-pc-linux-gnu/lib).
library_directory(/home/jeffd/.xsb/config/i686-pc-linux-gnu).
SWI-Prolog behaves the way Learn Prolog Now describes and outputs the contents of both files and dynamically added rules:
?- consult('test.P').
% test.P compiled 0.00 sec, 1,192 bytes
true.
?- assert(testing(c,d)).
true.
?- listing.
test(a, b).
% Foreign: rl_read_history/1
:- dynamic testing/2.
testing(c, d).
% Foreign: rl_write_history/1
% Foreign: rl_add_history/1
% Foreign: rl_read_init_file/1
true.
精彩评论