如何获得特定知识库的列表?
How to get a listing of a specific knowledge base?
假设文件foobar.pl
在当前工作
目录包含以下最小知识库:
foo(bar).
foo(baz).
frobozz.
如果我开始 swi-prolog
(通过 运行ning swipl
命令),然后立即 运行
?- [foobar].
% foobar compiled 0.00 sec, 4 clauses
true.
?- listing.
...foobar
的内容丢失在超过 100 行无关输出的海洋中。
如何将 listing
的输出限制为 foobar
?
或者,我如何将其限制为我已明确 consult
ed 的那些知识库的内容?
我确实查看了 docs 的 listing/1
和 listing/0
,但找不到任何有用的信息:
listing/1
List predicates specified by Pred. Pred may be a predicate name (atom), which lists all predicates with this name, regardless of their arity. It can also be a predicate indicator (/ or //), possibly qualified with a module. For example: ?- listing(lists:member/2)..
A listing is produced by enumerating the clauses of the predicate using clause/2 and printing each clause using portray_clause/1. This implies that the variable names are generated (A, B, ... ) and the layout is defined by rules in portray_clause/1.
listing/0
List all predicates from the calling module using listing/1. For example, ?- listing. lists clauses in the default user module and ?- lists:listing. lists the clauses in the module lists.
当然,我确实尝试了以下无用的想法:
?- foobar:listing.
true.
在 SWI-Prolog 中,您可以使用 module/2 指令 限制加载子句的范围。 IE。你的文件 foobar.pl
应该变成(例如)
:- module(foobar, [foo/1]).
foo(bar).
foo(baz).
frobozz.
您可以轻松地将普通 Prolog 文件的内容加载到模块中。例如:
?- fb:consult(foobar).
true
然后调用:
?- fb:listing.
foo(bar).
foo(baz).
frobozz.
true.
或者只列出一个特定的谓词:
?- fb:listing(foo/1).
foo(bar).
foo(baz).
true.
假设文件foobar.pl
在当前工作
目录包含以下最小知识库:
foo(bar).
foo(baz).
frobozz.
如果我开始 swi-prolog
(通过 运行ning swipl
命令),然后立即 运行
?- [foobar].
% foobar compiled 0.00 sec, 4 clauses
true.
?- listing.
...foobar
的内容丢失在超过 100 行无关输出的海洋中。
如何将 listing
的输出限制为 foobar
?
或者,我如何将其限制为我已明确 consult
ed 的那些知识库的内容?
我确实查看了 docs 的 listing/1
和 listing/0
,但找不到任何有用的信息:
listing/1 List predicates specified by Pred. Pred may be a predicate name (atom), which lists all predicates with this name, regardless of their arity. It can also be a predicate indicator (/ or //), possibly qualified with a module. For example: ?- listing(lists:member/2)..
A listing is produced by enumerating the clauses of the predicate using clause/2 and printing each clause using portray_clause/1. This implies that the variable names are generated (A, B, ... ) and the layout is defined by rules in portray_clause/1.
listing/0 List all predicates from the calling module using listing/1. For example, ?- listing. lists clauses in the default user module and ?- lists:listing. lists the clauses in the module lists.
当然,我确实尝试了以下无用的想法:
?- foobar:listing.
true.
在 SWI-Prolog 中,您可以使用 module/2 指令 限制加载子句的范围。 IE。你的文件 foobar.pl
应该变成(例如)
:- module(foobar, [foo/1]).
foo(bar).
foo(baz).
frobozz.
您可以轻松地将普通 Prolog 文件的内容加载到模块中。例如:
?- fb:consult(foobar).
true
然后调用:
?- fb:listing.
foo(bar).
foo(baz).
frobozz.
true.
或者只列出一个特定的谓词:
?- fb:listing(foo/1).
foo(bar).
foo(baz).
true.