Uses stderr
The predicate print_message/2 is used by the system and libraries to print messages.
It prints them to stderr though, so you cannot capture them with with_output_to/2 for example.
One day it might be interesting to hook those into a logging system.
Doc needs help
Missing is the message kind "query".
Example for extension
This code is amazing but it would really help to separate it out into task-specific submodules. Either Jan has a large short-term memory or my editor is inappropriate.
As an example from file prolog_pack.pl
(module prolog_pack
)
The call to print a message as found in some clause:
print_message(warning, pack(no_pack_installed(Name)))
To the end of the file, a message text is declared thusly (comments added)
% We will be extending nonterminal prolog:message//1 % prolog:message//1 is an application of DCG to generate a list of terms % to be emitted to a stream or the terminal :- multifile prolog:message//1. % And it is extended such that when called with pack(Message) as argument, % (thus indicating that we would like to have something "pack"-relevant % emitted) % it calls the DCG rule messages//1 in the current module with % the Message term: prolog:message(pack(Message)) --> message(Message). % Now come the rules form message//1, declared "discontinguous" as % helper predicates are intermixed. :- discontiguous message//1, label//1. % And at some point, the rule that generates the entries for the list of terms message(no_pack_installed(Pack)) --> [ 'No pack ~q installed. Use ?- pack_list(Pattern) to search'-[Pack] ].
Thus if we call
print_message(warning, pack(no_pack_installed(foo)))
the message printer will receive list elements
[ 'No pack ~q installed. Use ?- pack_list(Pattern) to search'-[foo] ].
format those into proper text and emit them to stdout.