【问题标题】:Simple question - XSB Prolog简单的问题 - XSB Prolog
【发布时间】:2010-03-11 14:12:12
【问题描述】:

我一头扎进了 prolog 的世界,但我似乎遇到了浅水!

关于本教程,我正在查看 prolog 中的数据库操作:Learn Prolog Now!

它表明我可以通过输入listing查看我的数据库

所以我试了一下,它基本上应该输出我的 .P 文件中的所有内容(事实、规则),但这就是我得到的,这是我的命令序列:

? consult('D:\Prolog\testfile.P').
[testfile.P loaded]

? listing.

library_directory(C:blahblahpathtoXSB)
library_directory(C:blahblahXSBpath)
{this is listed around 5 times)}

根据教程,此命令不应该显示 testfile.P 中的内容吗? 另外,在咨询 testfile.P 之后,我应该能够使用assert 添加更多事实,但它实际上并没有改变 testfile.P.. 中的任何内容?

任何想法

【问题讨论】:

    标签: prolog


    【解决方案1】:

    列表谓词的行为因 Prolog 解释器而异。 XSB documentation 解释了 Listing/0 的输出中将包含哪些代码:

    请注意,listing/0 没有列出任何 编译谓词,除非它们有 动态属性(见谓词 财产/2)。谓词获得 显式时的动态属性 声明为动态或自动 当某些条款时获得它 谓词在 数据库。

    使用一个非常简单的 test.P 文件,其中包含:

    test(a,b).
    

    这里是在 XSB 中使用 Listing/0 与咨询的文件和断言的规则。它只输出动态断言的规则,而不是文件的内容:

    | ?- 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 的行为方式类似于 Learn Prolog Now 描述和输出两个文件的内容以及动态添加的规则:

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

    【讨论】:

    • 这只是让我的谓词动态化的问题,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 2012-08-20
    相关资源
    最近更新 更多