简体   繁体   中英

How to get a listing of a specific knowledge base?

Suppose that the file foobar.pl in the current working directory contains the following minimal knowledgebase:

foo(bar).
foo(baz).
frobozz.

If I start swi-prolog (by running swipl at the command), and immediately run

?- [foobar].
% foobar compiled 0.00 sec, 4 clauses
true.

?- listing.

...the contents of foobar are lost in a sea of >100 lines of unrelated output.


How can I limit listing 's output to foobar ?

Alternatively, how can I limit it to contents of those knowledgebases I have explicitly consult ed?


I did look at the docs for listing/1 and listing/0 , but I could not find anything helpful:

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.


Of course, I did try the following useless idea:

?- foobar:listing.
true.

in SWI-Prolog, you can limit the scope of the loaded clauses with the module/2 directive . Ie your file foobar.pl should become (for instance)

:- module(foobar, [foo/1]).

foo(bar).
foo(baz).
frobozz.

You can load the contents of a plain Prolog file into a module easily. For example:

?- fb:consult(foobar).
true

And then call:

?- fb:listing.

foo(bar).
foo(baz).

frobozz.
true.

Or list just a specific predicate:

?- fb:listing(foo/1).
foo(bar).
foo(baz).

true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM