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.