View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2019, VU University Amsterdam
    7    All rights reserved.
    8
    9    Redistribution and use in source and binary forms, with or without
   10    modification, are permitted provided that the following conditions
   11    are met:
   12
   13    1. Redistributions of source code must retain the above copyright
   14       notice, this list of conditions and the following disclaimer.
   15
   16    2. Redistributions in binary form must reproduce the above copyright
   17       notice, this list of conditions and the following disclaimer in
   18       the documentation and/or other materials provided with the
   19       distribution.
   20
   21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   32    POSSIBILITY OF SUCH DAMAGE.
   33*/
   34
   35:- module(standard,
   36          [ error_write/1,              % @Message
   37            error_writeln/1,            % @Message
   38            console_write/1,            % @Message
   39            console_writeln/1,          % @Message
   40            warning/1,                  % @Message
   41            message/1,                  % @Message
   42            messageln/1                 % @Message
   43          ]).

XSB Term Writing to Designated I/O Streams

This module emulates the XSB dedicated term writing predicates from the standard module.

Compatibility
- XSB has a number of additional streams which we do not have. For now we send all messages to user_error. Onlt warning/1 is redirected through SWI-Prolog's print_message/2 interface. */
   55:- create_prolog_flag(warning_action, print_warning, [keep(true)]).
 error_write(@Term) is det
 error_writeln(@Term) is det
As write/1 and writeln/1 to user_error.
   62error_write(Term) :-
   63    write(user_error, Term).
   64error_writeln(Term) :-
   65    writeln(user_error, Term).
 console_write(@Term) is det
 console_writeln(@Term) is det
As write/1 and writeln/1 to user_error. The XSB version writes to STDFDBK. What does that mean?
   73console_write(Term) :-
   74    write(user_error, Term).
   75console_writeln(Term) :-
   76    writeln(user_error, Term).
 warning(@Message) is det
Print a warning. The behaviour depends on the flag warning_action, which can be one of:
print_warning
Re-direct the message to SWI-Prolog's print_message
error_warning
Throw error(xsb_warning(Message), _)
silent_warning
Ignore the warning.

If Message is a list or comma-list, the elements are concatenated without a space.

   93warning(Message) :-
   94    current_prolog_flag(warning_action, Action),
   95    warning(Action, Message).
   96
   97warning(silent_warning, _) :-
   98    !.
   99warning(error_warning, Term) :-
  100    !,
  101    throw(error(xsb_warning(Term), _)).
  102warning(_, Term) :-
  103    print_message(warning, xsb_warning(Term)).
  104
  105:- multifile
  106    prolog:message//1.  107
  108prolog:message(xsb_warning(Term)) -->
  109    [ 'XSB:'-[] ],
  110    xsb_warning(Term).
  111prolog:error_message(xsb_warning(Term)) -->
  112    [ 'XSB:'-[] ],
  113    xsb_warning(Term).
  114
  115xsb_warning(List) -->
  116    { is_list(List) },
  117    !,
  118    xsb_warning_list(List).
  119xsb_warning(Var) -->
  120    { var(Var) },
  121    !,
  122    [ '~w'-[Var] ].
  123xsb_warning((A,B)) -->
  124    !,
  125    xsb_warning(A),
  126    xsb_warning(B).
  127xsb_warning(Term) -->
  128    [ '~w'-[Term] ].
  129
  130xsb_warning_list([]) -->
  131    [].
  132xsb_warning_list([H|T]) -->
  133    [ '~w'-[H] ],
  134    xsb_warning_list(T).
 message(@Message) is det
 messageln(@Message) is det
Write message to user_error. As warning/1, Message can be a list or comma list.
Compatibility
- XSB. XSB writes to STDMSG. Possibly we should also redirect this through SWI-Prolog's print_message/2 interface.
  145message(Message) :-
  146    is_list(Message),
  147    !,
  148    maplist(message_elem, Message).
  149message(Var) :-
  150    var(Var),
  151    !,
  152    message_elem(Var).
  153message((A,B)) :-
  154    !,
  155    message(A),
  156    message(B).
  157message(Term) :-
  158    message_elem(Term).
  159
  160messageln(Term) :-
  161    message(Term),
  162    nl(user_error).
  163
  164message_elem(Term) :-
  165    write(user_error, Term)