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          ]).   44:- if(exists_source(library(dialect/xsb/timed_call))).   45:- use_module(library(dialect/xsb/timed_call)).   46:- export(timed_call/2).   47:- endif.

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. */
   59:- 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.
   66error_write(Term) :-
   67    write(user_error, Term).
   68error_writeln(Term) :-
   69    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?
   77console_write(Term) :-
   78    write(user_error, Term).
   79console_writeln(Term) :-
   80    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.

   97warning(Message) :-
   98    current_prolog_flag(warning_action, Action),
   99    warning(Action, Message).
  100
  101warning(silent_warning, _) :-
  102    !.
  103warning(error_warning, Term) :-
  104    !,
  105    throw(error(xsb_warning(Term), _)).
  106warning(_, Term) :-
  107    print_message(warning, xsb_warning(Term)).
  108
  109:- multifile
  110    prolog:message//1.  111
  112prolog:message(xsb_warning(Term)) -->
  113    [ 'XSB:'-[] ],
  114    xsb_warning(Term).
  115prolog:error_message(xsb_warning(Term)) -->
  116    [ 'XSB:'-[] ],
  117    xsb_warning(Term).
  118
  119xsb_warning(List) -->
  120    { is_list(List) },
  121    !,
  122    xsb_warning_list(List).
  123xsb_warning(Var) -->
  124    { var(Var) },
  125    !,
  126    [ '~w'-[Var] ].
  127xsb_warning((A,B)) -->
  128    !,
  129    xsb_warning(A),
  130    xsb_warning(B).
  131xsb_warning(Term) -->
  132    [ '~w'-[Term] ].
  133
  134xsb_warning_list([]) -->
  135    [].
  136xsb_warning_list([H|T]) -->
  137    [ '~w'-[H] ],
  138    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.
  149message(Message) :-
  150    is_list(Message),
  151    !,
  152    maplist(message_elem, Message).
  153message(Var) :-
  154    var(Var),
  155    !,
  156    message_elem(Var).
  157message((A,B)) :-
  158    !,
  159    message(A),
  160    message(B).
  161message(Term) :-
  162    message_elem(Term).
  163
  164messageln(Term) :-
  165    message(Term),
  166    nl(user_error).
  167
  168message_elem(Term) :-
  169    write(user_error, Term)