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) 1997-2021, University of Amsterdam 7 VU University Amsterdam 8 CWI, Amsterdam 9 SWI-Prolog Solutions b.v. 10 All rights reserved. 11 12 Redistribution and use in source and binary forms, with or without 13 modification, are permitted provided that the following conditions 14 are met: 15 16 1. Redistributions of source code must retain the above copyright 17 notice, this list of conditions and the following disclaimer. 18 19 2. Redistributions in binary form must reproduce the above copyright 20 notice, this list of conditions and the following disclaimer in 21 the documentation and/or other materials provided with the 22 distribution. 23 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 27 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 28 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 POSSIBILITY OF SUCH DAMAGE. 36*/ 37 38:- module('$messages', 39 [ print_message/2, % +Kind, +Term 40 print_message_lines/3, % +Stream, +Prefix, +Lines 41 message_to_string/2 % +Term, -String 42 ]). 43 44:- multifile 45 prolog:message//1, % entire message 46 prolog:error_message//1, % 1-st argument of error term 47 prolog:message_context//1, % Context of error messages 48 prolog:deprecated//1, % Deprecated features 49 prolog:message_location//1, % (File) location of error messages 50 prolog:message_line_element/2. % Extend printing 51:- '$hide'(( 52 prolog:message//1, 53 prolog:error_message//1, 54 prolog:message_context//1, 55 prolog:deprecated//1, 56 prolog:message_location//1, 57 prolog:message_line_element/2)). 58% Lang, Term versions 59:- multifile 60 prolog:message//2, % entire message 61 prolog:error_message//2, % 1-st argument of error term 62 prolog:message_context//2, % Context of error messages 63 prolog:message_location//2, % (File) location of error messages 64 prolog:deprecated//2. % Deprecated features 65:- '$hide'(( 66 prolog:message//2, 67 prolog:error_message//2, 68 prolog:message_context//2, 69 prolog:deprecated//2, 70 prolog:message_location//2)). 71 72:- discontiguous 73 prolog_message/3. 74 75:- public 76 translate_message//1, % +Message (deprecated) 77 prolog:translate_message//1. % +Message 78 79:- create_prolog_flag(message_context, [thread], []).
format(Fmt, Args)
format(Fmt)
103prologtranslate_message(Term) -->
104 translate_message(Term).
111translate_message(Term) --> 112 { nonvar(Term) }, 113 ( { message_lang(Lang) }, 114 prolog:message(Lang, Term) 115 ; prolog:message(Term) 116 ), 117 !. 118translate_message(Term) --> 119 { nonvar(Term) }, 120 translate_message2(Term), 121 !. 122translate_message(Term) --> 123 { nonvar(Term), 124 Term = error(_, _) 125 }, 126 [ 'Unknown exception: ~p'-[Term] ]. 127translate_message(Term) --> 128 [ 'Unknown message: ~p'-[Term] ]. 129 130translate_message2(Term) --> 131 prolog_message(Term). 132translate_message2(error(resource_error(stack), Context)) --> 133 !, 134 out_of_stack(Context). 135translate_message2(error(resource_error(tripwire(Wire, Context)), _)) --> 136 !, 137 tripwire_message(Wire, Context). 138translate_message2(error(existence_error(reset, Ball), SWI)) --> 139 swi_location(SWI), 140 tabling_existence_error(Ball, SWI). 141translate_message2(error(ISO, SWI)) --> 142 swi_location(SWI), 143 term_message(ISO), 144 swi_extra(SWI). 145translate_message2('$aborted') --> 146 [ 'Execution Aborted' ]. 147translate_message2(message_lines(Lines), L, T) :- % deal with old C-warning() 148 make_message_lines(Lines, L, T). 149translate_message2(format(Fmt, Args)) --> 150 [ Fmt-Args ]. 151 152make_message_lines([], T, T) :- !. 153make_message_lines([Last], ['~w'-[Last]|T], T) :- !. 154make_message_lines([L0|LT], ['~w'-[L0],nl|T0], T) :- 155 make_message_lines(LT, T0, T).
error(Format, ImplDefined)
exception terms. The ImplDefined argument is handled by
swi_location//2.163:- public term_message//1. 164term_message(Term) --> 165 {var(Term)}, 166 !, 167 [ 'Unknown error term: ~p'-[Term] ]. 168term_message(Term) --> 169 { message_lang(Lang) }, 170 prolog:error_message(Lang, Term), 171 !. 172term_message(Term) --> 173 prolog:error_message(Term), 174 !. 175term_message(Term) --> 176 iso_message(Term). 177term_message(Term) --> 178 swi_message(Term). 179term_message(Term) --> 180 [ 'Unknown error term: ~p'-[Term] ]. 181 182iso_message(resource_error(c_stack)) --> 183 out_of_c_stack. 184iso_message(resource_error(Missing)) --> 185 [ 'Not enough resources: ~w'-[Missing] ]. 186iso_message(type_error(evaluable, Actual)) --> 187 { callable(Actual) }, 188 [ 'Arithmetic: `~p'' is not a function'-[Actual] ]. 189iso_message(type_error(free_of_attvar, Actual)) --> 190 [ 'Type error: `~W'' contains attributed variables'- 191 [Actual,[portray(true), attributes(portray)]] ]. 192iso_message(type_error(Expected, Actual)) --> 193 [ 'Type error: `~w'' expected, found `~p'''-[Expected, Actual] ], 194 type_error_comment(Expected, Actual). 195iso_message(domain_error(Domain, Actual)) --> 196 [ 'Domain error: '-[] ], domain(Domain), 197 [ ' expected, found `~p'''-[Actual] ]. 198iso_message(instantiation_error) --> 199 [ 'Arguments are not sufficiently instantiated' ]. 200iso_message(uninstantiation_error(Var)) --> 201 [ 'Uninstantiated argument expected, found ~p'-[Var] ]. 202iso_message(representation_error(What)) --> 203 [ 'Cannot represent due to `~w'''-[What] ]. 204iso_message(permission_error(Action, Type, Object)) --> 205 permission_error(Action, Type, Object). 206iso_message(evaluation_error(Which)) --> 207 [ 'Arithmetic: evaluation error: `~p'''-[Which] ]. 208iso_message(existence_error(procedure, Proc)) --> 209 [ 'Unknown procedure: ~q'-[Proc] ], 210 unknown_proc_msg(Proc). 211iso_message(existence_error(answer_variable, Var)) --> 212 [ '$~w was not bound by a previous query'-[Var] ]. 213iso_message(existence_error(matching_rule, Goal)) --> 214 [ 'No rule matches ~p'-[Goal] ]. 215iso_message(existence_error(Type, Object)) --> 216 [ '~w `~p'' does not exist'-[Type, Object] ]. 217iso_message(existence_error(Type, Object, In)) --> % not ISO 218 [ '~w `~p'' does not exist in ~p'-[Type, Object, In] ]. 219iso_message(busy(Type, Object)) --> 220 [ '~w `~p'' is busy'-[Type, Object] ]. 221iso_message(syntax_error(swi_backslash_newline)) --> 222 [ 'Deprecated ... \\<newline><white>*. Use \\c' ]. 223iso_message(syntax_error(Id)) --> 224 [ 'Syntax error: ' ], 225 syntax_error(Id). 226iso_message(occurs_check(Var, In)) --> 227 [ 'Cannot unify ~p with ~p: would create an infinite tree'-[Var, In] ].
234permission_error(Action, built_in_procedure, Pred) --> 235 { user_predicate_indicator(Pred, PI) 236 }, 237 [ 'No permission to ~w built-in predicate `~p'''-[Action, PI] ], 238 ( {Action \== export} 239 -> [ nl, 240 'Use :- redefine_system_predicate(+Head) if redefinition is intended' 241 ] 242 ; [] 243 ). 244permission_error(import_into(Dest), procedure, Pred) --> 245 [ 'No permission to import ~p into ~w'-[Pred, Dest] ]. 246permission_error(Action, static_procedure, Proc) --> 247 [ 'No permission to ~w static procedure `~p'''-[Action, Proc] ], 248 defined_definition('Defined', Proc). 249permission_error(input, stream, Stream) --> 250 [ 'No permission to read from output stream `~p'''-[Stream] ]. 251permission_error(output, stream, Stream) --> 252 [ 'No permission to write to input stream `~p'''-[Stream] ]. 253permission_error(input, text_stream, Stream) --> 254 [ 'No permission to read bytes from TEXT stream `~p'''-[Stream] ]. 255permission_error(output, text_stream, Stream) --> 256 [ 'No permission to write bytes to TEXT stream `~p'''-[Stream] ]. 257permission_error(input, binary_stream, Stream) --> 258 [ 'No permission to read characters from binary stream `~p'''-[Stream] ]. 259permission_error(output, binary_stream, Stream) --> 260 [ 'No permission to write characters to binary stream `~p'''-[Stream] ]. 261permission_error(open, source_sink, alias(Alias)) --> 262 [ 'No permission to reuse alias "~p": already taken'-[Alias] ]. 263permission_error(tnot, non_tabled_procedure, Pred) --> 264 [ 'The argument of tnot/1 is not tabled: ~p'-[Pred] ]. 265permission_error(assert, procedure, Pred) --> 266 { '$pi_head'(Pred, Head), 267 predicate_property(Head, ssu) 268 }, 269 [ '~p: an SSU (Head => Body) predicate cannot have normal Prolog clauses'- 270 [Pred] ]. 271permission_error(Action, Type, Object) --> 272 [ 'No permission to ~w ~w `~p'''-[Action, Type, Object] ]. 273 274 275unknown_proc_msg(_:(^)/2) --> 276 !, 277 unknown_proc_msg((^)/2). 278unknown_proc_msg((^)/2) --> 279 !, 280 [nl, ' ^/2 can only appear as the 2nd argument of setof/3 and bagof/3']. 281unknown_proc_msg((:-)/2) --> 282 !, 283 [nl, ' Rules must be loaded from a file'], 284 faq('ToplevelMode'). 285unknown_proc_msg((=>)/2) --> 286 !, 287 [nl, ' Rules must be loaded from a file'], 288 faq('ToplevelMode'). 289unknown_proc_msg((:-)/1) --> 290 !, 291 [nl, ' Directives must be loaded from a file'], 292 faq('ToplevelMode'). 293unknown_proc_msg((?-)/1) --> 294 !, 295 [nl, ' ?- is the Prolog prompt'], 296 faq('ToplevelMode'). 297unknown_proc_msg(Proc) --> 298 { dwim_predicates(Proc, Dwims) }, 299 ( {Dwims \== []} 300 -> [nl, ' However, there are definitions for:', nl], 301 dwim_message(Dwims) 302 ; [] 303 ). 304 305dependency_error(shared(Shared), private(Private)) --> 306 [ 'Shared table for ~p may not depend on private ~p'-[Shared, Private] ]. 307dependency_error(Dep, monotonic(On)) --> 308 { '$pi_head'(PI, Dep), 309 '$pi_head'(MPI, On) 310 }, 311 [ 'Dependent ~p on monotonic predicate ~p is not monotonic or incremental'- 312 [PI, MPI] 313 ]. 314 315faq(Page) --> 316 [nl, ' See FAQ at https://www.swi-prolog.org/FAQ/', Page, '.txt' ]. 317 318type_error_comment(_Expected, Actual) --> 319 { type_of(Actual, Type), 320 ( sub_atom(Type, 0, 1, _, First), 321 memberchk(First, [a,e,i,o,u]) 322 -> Article = an 323 ; Article = a 324 ) 325 }, 326 [ ' (~w ~w)'-[Article, Type] ]. 327 328type_of(Term, Type) :- 329 ( attvar(Term) -> Type = attvar 330 ; var(Term) -> Type = var 331 ; atom(Term) -> Type = atom 332 ; integer(Term) -> Type = integer 333 ; string(Term) -> Type = string 334 ; Term == [] -> Type = empty_list 335 ; blob(Term, BlobT) -> blob_type(BlobT, Type) 336 ; rational(Term) -> Type = rational 337 ; float(Term) -> Type = float 338 ; is_stream(Term) -> Type = stream 339 ; is_dict(Term) -> Type = dict 340 ; is_list(Term) -> Type = list 341 ; cyclic_term(Term) -> Type = cyclic 342 ; compound(Term) -> Type = compound 343 ; Type = unknown 344 ). 345 346blob_type(BlobT, Type) :- 347 atom_concat(BlobT, '_reference', Type). 348 349syntax_error(end_of_clause) --> 350 [ 'Unexpected end of clause' ]. 351syntax_error(end_of_clause_expected) --> 352 [ 'End of clause expected' ]. 353syntax_error(end_of_file) --> 354 [ 'Unexpected end of file' ]. 355syntax_error(end_of_file_in_block_comment) --> 356 [ 'End of file in /* ... */ comment' ]. 357syntax_error(end_of_file_in_quoted(Quote)) --> 358 [ 'End of file in quoted ' ], 359 quoted_type(Quote). 360syntax_error(illegal_number) --> 361 [ 'Illegal number' ]. 362syntax_error(long_atom) --> 363 [ 'Atom too long (see style_check/1)' ]. 364syntax_error(long_string) --> 365 [ 'String too long (see style_check/1)' ]. 366syntax_error(operator_clash) --> 367 [ 'Operator priority clash' ]. 368syntax_error(operator_expected) --> 369 [ 'Operator expected' ]. 370syntax_error(operator_balance) --> 371 [ 'Unbalanced operator' ]. 372syntax_error(quoted_punctuation) --> 373 [ 'Operand expected, unquoted comma or bar found' ]. 374syntax_error(list_rest) --> 375 [ 'Unexpected comma or bar in rest of list' ]. 376syntax_error(cannot_start_term) --> 377 [ 'Illegal start of term' ]. 378syntax_error(punct(Punct, End)) --> 379 [ 'Unexpected `~w\' before `~w\''-[Punct, End] ]. 380syntax_error(undefined_char_escape(C)) --> 381 [ 'Unknown character escape in quoted atom or string: `\\~w\''-[C] ]. 382syntax_error(void_not_allowed) --> 383 [ 'Empty argument list "()"' ]. 384syntax_error(Message) --> 385 [ '~w'-[Message] ]. 386 387quoted_type('\'') --> [atom]. 388quoted_type('\"') --> { current_prolog_flag(double_quotes, Type) }, [Type-[]]. 389quoted_type('\`') --> { current_prolog_flag(back_quotes, Type) }, [Type-[]]. 390 391domain(range(Low,High)) --> 392 !, 393 ['[~q..~q]'-[Low,High] ]. 394domain(Domain) --> 395 ['`~w\''-[Domain] ].
402tabling_existence_error(Ball, Context) --> 403 { table_shift_ball(Ball) }, 404 [ 'Tabling dependency error' ], 405 swi_extra(Context). 406 407table_shift_ball(dependency(_Head)). 408table_shift_ball(dependency(_Skeleton, _Trie, _Mono)). 409table_shift_ball(call_info(_Skeleton, _Status)). 410table_shift_ball(call_info(_GenSkeleton, _Skeleton, _Status)).
416dwim_predicates(Module:Name/_Arity, Dwims) :- 417 !, 418 findall(Dwim, dwim_predicate(Module:Name, Dwim), Dwims). 419dwim_predicates(Name/_Arity, Dwims) :- 420 findall(Dwim, dwim_predicate(user:Name, Dwim), Dwims). 421 422dwim_message([]) --> []. 423dwim_message([M:Head|T]) --> 424 { hidden_module(M), 425 !, 426 functor(Head, Name, Arity) 427 }, 428 [ ' ~q'-[Name/Arity], nl ], 429 dwim_message(T). 430dwim_message([Module:Head|T]) --> 431 !, 432 { functor(Head, Name, Arity) 433 }, 434 [ ' ~q'-[Module:Name/Arity], nl], 435 dwim_message(T). 436dwim_message([Head|T]) --> 437 {functor(Head, Name, Arity)}, 438 [ ' ~q'-[Name/Arity], nl], 439 dwim_message(T). 440 441 442swi_message(io_error(Op, Stream)) --> 443 [ 'I/O error in ~w on stream ~p'-[Op, Stream] ]. 444swi_message(thread_error(TID, false)) --> 445 [ 'Thread ~p died due to failure:'-[TID] ]. 446swi_message(thread_error(TID, exception(Error))) --> 447 [ 'Thread ~p died abnormally:'-[TID], nl ], 448 translate_message(Error). 449swi_message(dependency_error(Tabled, DependsOn)) --> 450 dependency_error(Tabled, DependsOn). 451swi_message(shell(execute, Cmd)) --> 452 [ 'Could not execute `~w'''-[Cmd] ]. 453swi_message(shell(signal(Sig), Cmd)) --> 454 [ 'Caught signal ~d on `~w'''-[Sig, Cmd] ]. 455swi_message(format(Fmt, Args)) --> 456 [ Fmt-Args ]. 457swi_message(signal(Name, Num)) --> 458 [ 'Caught signal ~d (~w)'-[Num, Name] ]. 459swi_message(limit_exceeded(Limit, MaxVal)) --> 460 [ 'Exceeded ~w limit (~w)'-[Limit, MaxVal] ]. 461swi_message(goal_failed(Goal)) --> 462 [ 'goal unexpectedly failed: ~p'-[Goal] ]. 463swi_message(shared_object(_Action, Message)) --> % Message = dlerror() 464 [ '~w'-[Message] ]. 465swi_message(system_error(Error)) --> 466 [ 'error in system call: ~w'-[Error] 467 ]. 468swi_message(system_error) --> 469 [ 'error in system call' 470 ]. 471swi_message(failure_error(Goal)) --> 472 [ 'Goal failed: ~p'-[Goal] ]. 473swi_message(timeout_error(Op, Stream)) --> 474 [ 'Timeout in ~w from ~p'-[Op, Stream] ]. 475swi_message(not_implemented(Type, What)) --> 476 [ '~w `~p\' is not implemented in this version'-[Type, What] ]. 477swi_message(context_error(nodirective, Goal)) --> 478 { goal_to_predicate_indicator(Goal, PI) }, 479 [ 'Wrong context: ~p can only be used in a directive'-[PI] ]. 480swi_message(context_error(edit, no_default_file)) --> 481 ( { current_prolog_flag(windows, true) } 482 -> [ 'Edit/0 can only be used after opening a \c 483 Prolog file by double-clicking it' ] 484 ; [ 'Edit/0 can only be used with the "-s file" commandline option' 485 ] 486 ), 487 [ nl, 'Use "?- edit(Topic)." or "?- emacs."' ]. 488swi_message(context_error(function, meta_arg(S))) --> 489 [ 'Functions are not (yet) supported for meta-arguments of type ~q'-[S] ]. 490swi_message(format_argument_type(Fmt, Arg)) --> 491 [ 'Illegal argument to format sequence ~~~w: ~p'-[Fmt, Arg] ]. 492swi_message(format(Msg)) --> 493 [ 'Format error: ~w'-[Msg] ]. 494swi_message(conditional_compilation_error(unterminated, File:Line)) --> 495 [ 'Unterminated conditional compilation from '-[], url(File:Line) ]. 496swi_message(conditional_compilation_error(no_if, What)) --> 497 [ ':- ~w without :- if'-[What] ]. 498swi_message(duplicate_key(Key)) --> 499 [ 'Duplicate key: ~p'-[Key] ]. 500swi_message(initialization_error(failed, Goal, File:Line)) --> 501 !, 502 [ url(File:Line), ': ~p: false'-[Goal] ]. 503swi_message(initialization_error(Error, Goal, File:Line)) --> 504 [ url(File:Line), ': ~p '-[Goal] ], 505 translate_message(Error). 506swi_message(determinism_error(PI, det, Found, property)) --> 507 ( { '$pi_head'(user:PI, Head), 508 predicate_property(Head, det) 509 } 510 -> [ 'Deterministic procedure ~p'-[PI] ] 511 ; [ 'Procedure ~p called from a deterministic procedure'-[PI] ] 512 ), 513 det_error(Found). 514swi_message(determinism_error(PI, det, fail, guard)) --> 515 [ 'Procedure ~p failed after $-guard'-[PI] ]. 516swi_message(determinism_error(PI, det, fail, guard_in_caller)) --> 517 [ 'Procedure ~p failed after $-guard in caller'-[PI] ]. 518swi_message(determinism_error(Goal, det, fail, goal)) --> 519 [ 'Goal ~p failed'-[Goal] ]. 520swi_message(determinism_error(Goal, det, nondet, goal)) --> 521 [ 'Goal ~p succeeded with a choice point'-[Goal] ]. 522swi_message(qlf_format_error(File, Message)) --> 523 [ '~w: Invalid QLF file: ~w'-[File, Message] ]. 524swi_message(goal_expansion_error(bound, Term)) --> 525 [ 'Goal expansion bound a variable to ~p'-[Term] ]. 526 527det_error(nondet) --> 528 [ ' succeeded with a choicepoint'- [] ]. 529det_error(fail) --> 530 [ ' failed'- [] ].
error(Formal, ImplDefined)
from the
ImplDefined term.538:- public swi_location//1. 539swi_location(X) --> 540 { var(X) }, 541 !. 542swi_location(Context) --> 543 { message_lang(Lang) }, 544 prolog:message_location(Lang, Context), 545 !. 546swi_location(Context) --> 547 prolog:message_location(Context), 548 !. 549swi_location(context(Caller, _Msg)) --> 550 { ground(Caller) }, 551 !, 552 caller(Caller). 553swi_location(file(Path, Line, -1, _CharNo)) --> 554 !, 555 [ url(Path:Line), ': ' ]. 556swi_location(file(Path, Line, LinePos, _CharNo)) --> 557 [ url(Path:Line:LinePos), ': ' ]. 558swi_location(stream(Stream, Line, LinePos, CharNo)) --> 559 ( { is_stream(Stream), 560 stream_property(Stream, file_name(File)) 561 } 562 -> swi_location(file(File, Line, LinePos, CharNo)) 563 ; [ 'Stream ~w:~d:~d '-[Stream, Line, LinePos] ] 564 ). 565swi_location(autoload(File:Line)) --> 566 [ url(File:Line), ': ' ]. 567swi_location(_) --> 568 []. 569 570caller(system:'$record_clause'/3) --> 571 !, 572 []. 573caller(Module:Name/Arity) --> 574 !, 575 ( { \+ hidden_module(Module) } 576 -> [ '~q:~q/~w: '-[Module, Name, Arity] ] 577 ; [ '~q/~w: '-[Name, Arity] ] 578 ). 579caller(Name/Arity) --> 580 [ '~q/~w: '-[Name, Arity] ]. 581caller(Caller) --> 582 [ '~p: '-[Caller] ].
error(Formal,
ImplDefined)
that is printed after the core of the message.
593swi_extra(X) --> 594 { var(X) }, 595 !, 596 []. 597swi_extra(Context) --> 598 { message_lang(Lang) }, 599 prolog:message_context(Lang, Context), 600 !. 601swi_extra(Context) --> 602 prolog:message_context(Context). 603swi_extra(context(_, Msg)) --> 604 { nonvar(Msg), 605 Msg \== '' 606 }, 607 !, 608 swi_comment(Msg). 609swi_extra(string(String, CharPos)) --> 610 { sub_string(String, 0, CharPos, _, Before), 611 sub_string(String, CharPos, _, 0, After) 612 }, 613 [ nl, '~w'-[Before], nl, '** here **', nl, '~w'-[After] ]. 614swi_extra(_) --> 615 []. 616 617swi_comment(already_from(Module)) --> 618 !, 619 [ ' (already imported from ~q)'-[Module] ]. 620swi_comment(directory(_Dir)) --> 621 !, 622 [ ' (is a directory)' ]. 623swi_comment(not_a_directory(_Dir)) --> 624 !, 625 [ ' (is not a directory)' ]. 626swi_comment(Msg) --> 627 [ ' (~w)'-[Msg] ]. 628 629 630thread_context --> 631 { thread_self(Me), Me \== main, thread_property(Me, id(Id)) }, 632 !, 633 ['[Thread ~w] '-[Id]]. 634thread_context --> 635 []. 636 637 /******************************* 638 * NORMAL MESSAGES * 639 *******************************/ 640 641prolog_message(welcome) --> 642 [ 'Welcome to SWI-Prolog (' ], 643 prolog_message(threads), 644 prolog_message(address_bits), 645 ['version ' ], 646 prolog_message(version), 647 [ ')', nl ], 648 prolog_message(copyright), 649 [ nl ], 650 translate_message(user_versions), 651 [ nl ], 652 prolog_message(documentaton), 653 [ nl, nl ]. 654prolog_message(user_versions) --> 655 ( { findall(Msg, prolog:version_msg(Msg), Msgs), 656 Msgs \== [] 657 } 658 -> [nl], 659 user_version_messages(Msgs) 660 ; [] 661 ). 662prolog_message(deprecated(Term)) --> 663 { nonvar(Term) }, 664 ( { message_lang(Lang) }, 665 prolog:deprecated(Lang, Term) 666 -> [] 667 ; prolog:deprecated(Term) 668 -> [] 669 ; deprecated(Term) 670 ). 671prolog_message(unhandled_exception(E)) --> 672 { nonvar(E) }, 673 [ 'Unhandled exception: ' ], 674 ( translate_message(E) 675 -> [] 676 ; [ '~p'-[E] ] 677 ).
681prolog_message(initialization_error(_, E, File:Line)) --> 682 !, 683 [ url(File:Line), 684 ': Initialization goal raised exception:', nl 685 ], 686 translate_message(E). 687prolog_message(initialization_error(Goal, E, _)) --> 688 [ 'Initialization goal ~p raised exception:'-[Goal], nl ], 689 translate_message(E). 690prolog_message(initialization_failure(_Goal, File:Line)) --> 691 !, 692 [ url(File:Line), 693 ': Initialization goal failed'-[] 694 ]. 695prolog_message(initialization_failure(Goal, _)) --> 696 [ 'Initialization goal failed: ~p'-[Goal] 697 ]. 698prolog_message(initialization_exception(E)) --> 699 [ 'Prolog initialisation failed:', nl ], 700 translate_message(E). 701prolog_message(init_goal_syntax(Error, Text)) --> 702 !, 703 [ '-g ~w: '-[Text] ], 704 translate_message(Error). 705prolog_message(init_goal_failed(failed, @(Goal,File:Line))) --> 706 !, 707 [ url(File:Line), ': ~p: false'-[Goal] ]. 708prolog_message(init_goal_failed(Error, @(Goal,File:Line))) --> 709 !, 710 [ url(File:Line), ': ~p '-[Goal] ], 711 translate_message(Error). 712prolog_message(init_goal_failed(failed, Text)) --> 713 !, 714 [ '-g ~w: false'-[Text] ]. 715prolog_message(init_goal_failed(Error, Text)) --> 716 !, 717 [ '-g ~w: '-[Text] ], 718 translate_message(Error). 719prolog_message(goal_failed(Context, Goal)) --> 720 [ 'Goal (~w) failed: ~p'-[Context, Goal] ]. 721prolog_message(no_current_module(Module)) --> 722 [ '~w is not a current module (created)'-[Module] ]. 723prolog_message(commandline_arg_type(Flag, Arg)) --> 724 [ 'Bad argument to commandline option -~w: ~w'-[Flag, Arg] ]. 725prolog_message(missing_feature(Name)) --> 726 [ 'This version of SWI-Prolog does not support ~w'-[Name] ]. 727prolog_message(singletons(_Term, List)) --> 728 [ 'Singleton variables: ~w'-[List] ]. 729prolog_message(multitons(_Term, List)) --> 730 [ 'Singleton-marked variables appearing more than once: ~w'-[List] ]. 731prolog_message(profile_no_cpu_time) --> 732 [ 'No CPU-time info. Check the SWI-Prolog manual for details' ]. 733prolog_message(non_ascii(Text, Type)) --> 734 [ 'Unquoted ~w with non-portable characters: ~w'-[Type, Text] ]. 735prolog_message(io_warning(Stream, Message)) --> 736 { stream_property(Stream, position(Position)), 737 !, 738 stream_position_data(line_count, Position, LineNo), 739 stream_position_data(line_position, Position, LinePos), 740 ( stream_property(Stream, file_name(File)) 741 -> Obj = File 742 ; Obj = Stream 743 ) 744 }, 745 [ '~p:~d:~d: ~w'-[Obj, LineNo, LinePos, Message] ]. 746prolog_message(io_warning(Stream, Message)) --> 747 [ 'stream ~p: ~w'-[Stream, Message] ]. 748prolog_message(option_usage(pldoc)) --> 749 [ 'Usage: --pldoc[=port]' ]. 750prolog_message(interrupt(begin)) --> 751 [ 'Action (h for help) ? ', flush ]. 752prolog_message(interrupt(end)) --> 753 [ 'continue' ]. 754prolog_message(interrupt(trace)) --> 755 [ 'continue (trace mode)' ]. 756prolog_message(unknown_in_module_user) --> 757 [ 'Using a non-error value for unknown in the global module', nl, 758 'causes most of the development environment to stop working.', nl, 759 'Please use :- dynamic or limit usage of unknown to a module.', nl, 760 'See https://www.swi-prolog.org/howto/database.html' 761 ]. 762prolog_message(untable(PI)) --> 763 [ 'Reconsult: removed tabling for ~p'-[PI] ]. 764 765 766 /******************************* 767 * LOADING FILES * 768 *******************************/ 769 770prolog_message(modify_active_procedure(Who, What)) --> 771 [ '~p: modified active procedure ~p'-[Who, What] ]. 772prolog_message(load_file(failed(user:File))) --> 773 [ 'Failed to load ~p'-[File] ]. 774prolog_message(load_file(failed(Module:File))) --> 775 [ 'Failed to load ~p into module ~p'-[File, Module] ]. 776prolog_message(load_file(failed(File))) --> 777 [ 'Failed to load ~p'-[File] ]. 778prolog_message(mixed_directive(Goal)) --> 779 [ 'Cannot pre-compile mixed load/call directive: ~p'-[Goal] ]. 780prolog_message(cannot_redefine_comma) --> 781 [ 'Full stop in clause-body? Cannot redefine ,/2' ]. 782prolog_message(illegal_autoload_index(Dir, Term)) --> 783 [ 'Illegal term in INDEX file of directory ~w: ~w'-[Dir, Term] ]. 784prolog_message(redefined_procedure(Type, Proc)) --> 785 [ 'Redefined ~w procedure ~p'-[Type, Proc] ], 786 defined_definition('Previously defined', Proc). 787prolog_message(declare_module(Module, abolish(Predicates))) --> 788 [ 'Loading module ~w abolished: ~p'-[Module, Predicates] ]. 789prolog_message(import_private(Module, Private)) --> 790 [ 'import/1: ~p is not exported (still imported into ~q)'- 791 [Private, Module] 792 ]. 793prolog_message(ignored_weak_import(Into, From:PI)) --> 794 [ 'Local definition of ~p overrides weak import from ~q'- 795 [Into:PI, From] 796 ]. 797prolog_message(undefined_export(Module, PI)) --> 798 [ 'Exported procedure ~q:~q is not defined'-[Module, PI] ]. 799prolog_message(no_exported_op(Module, Op)) --> 800 [ 'Operator ~q:~q is not exported (still defined)'-[Module, Op] ]. 801prolog_message(discontiguous((-)/2,_)) --> 802 prolog_message(minus_in_identifier). 803prolog_message(discontiguous(Proc,Current)) --> 804 [ 'Clauses of ', ansi(code, '~p', [Proc]), 805 ' are not together in the source-file', nl ], 806 current_definition(Proc, 'Earlier definition at '), 807 [ 'Current predicate: ', ansi(code, '~p', [Current]), nl, 808 'Use ', ansi(code, ':- discontiguous ~p.', [Proc]), 809 ' to suppress this message' 810 ]. 811prolog_message(decl_no_effect(Goal)) --> 812 [ 'Deprecated declaration has no effect: ~p'-[Goal] ]. 813prolog_message(load_file(start(Level, File))) --> 814 [ '~|~t~*+Loading '-[Level] ], 815 load_file(File), 816 [ ' ...' ]. 817prolog_message(include_file(start(Level, File))) --> 818 [ '~|~t~*+include '-[Level] ], 819 load_file(File), 820 [ ' ...' ]. 821prolog_message(include_file(done(Level, File))) --> 822 [ '~|~t~*+included '-[Level] ], 823 load_file(File). 824prolog_message(load_file(done(Level, File, Action, Module, Time, Clauses))) --> 825 [ '~|~t~*+'-[Level] ], 826 load_file(File), 827 [ ' ~w'-[Action] ], 828 load_module(Module), 829 [ ' ~2f sec, ~D clauses'-[Time, Clauses] ]. 830prolog_message(dwim_undefined(Goal, Alternatives)) --> 831 { goal_to_predicate_indicator(Goal, Pred) 832 }, 833 [ 'Unknown procedure: ~q'-[Pred], nl, 834 ' However, there are definitions for:', nl 835 ], 836 dwim_message(Alternatives). 837prolog_message(dwim_correct(Into)) --> 838 [ 'Correct to: ~q? '-[Into], flush ]. 839prolog_message(error(loop_error(Spec), file_search(Used))) --> 840 [ 'File search: too many levels of indirections on: ~p'-[Spec], nl, 841 ' Used alias expansions:', nl 842 ], 843 used_search(Used). 844prolog_message(minus_in_identifier) --> 845 [ 'The "-" character should not be used to separate words in an', nl, 846 'identifier. Check the SWI-Prolog FAQ for details.' 847 ]. 848prolog_message(qlf(removed_after_error(File))) --> 849 [ 'Removed incomplete QLF file ~w'-[File] ]. 850prolog_message(qlf(recompile(Spec,_Pl,_Qlf,Reason))) --> 851 [ '~p: recompiling QLF file'-[Spec] ], 852 qlf_recompile_reason(Reason). 853prolog_message(qlf(can_not_recompile(Spec,QlfFile,_Reason))) --> 854 [ '~p: can not recompile "~w" (access denied)'-[Spec, QlfFile], nl, 855 '\tLoading from source'-[] 856 ]. 857prolog_message(qlf(system_lib_out_of_date(Spec,QlfFile))) --> 858 [ '~p: can not recompile "~w" (access denied)'-[Spec, QlfFile], nl, 859 '\tLoading QlfFile'-[] 860 ]. 861prolog_message(redefine_module(Module, OldFile, File)) --> 862 [ 'Module "~q" already loaded from ~w.'-[Module, OldFile], nl, 863 'Wipe and reload from ~w? '-[File], flush 864 ]. 865prolog_message(redefine_module_reply) --> 866 [ 'Please answer y(es), n(o) or a(bort)' ]. 867prolog_message(reloaded_in_module(Absolute, OldContext, LM)) --> 868 [ '~w was previously loaded in module ~w'-[Absolute, OldContext], nl, 869 '\tnow it is reloaded into module ~w'-[LM] ]. 870prolog_message(expected_layout(Expected, Pos)) --> 871 [ 'Layout data: expected ~w, found: ~p'-[Expected, Pos] ]. 872 873defined_definition(Message, Spec) --> 874 { strip_module(user:Spec, M, Name/Arity), 875 functor(Head, Name, Arity), 876 predicate_property(M:Head, file(File)), 877 predicate_property(M:Head, line_count(Line)) 878 }, 879 !, 880 [ nl, '~w at '-[Message], url(File:Line) ]. 881defined_definition(_, _) --> []. 882 883used_search([]) --> 884 []. 885used_search([Alias=Expanded|T]) --> 886 [ ' file_search_path(~p, ~p)'-[Alias, Expanded], nl ], 887 used_search(T). 888 889load_file(file(Spec, _Path)) --> 890 ( {atomic(Spec)} 891 -> [ '~w'-[Spec] ] 892 ; [ '~p'-[Spec] ] 893 ). 894%load_file(file(_, Path)) --> 895% [ '~w'-[Path] ]. 896 897load_module(user) --> !. 898load_module(system) --> !. 899load_module(Module) --> 900 [ ' into ~w'-[Module] ]. 901 902goal_to_predicate_indicator(Goal, PI) :- 903 strip_module(Goal, Module, Head), 904 callable_name_arity(Head, Name, Arity), 905 user_predicate_indicator(Module:Name/Arity, PI). 906 907callable_name_arity(Goal, Name, Arity) :- 908 compound(Goal), 909 !, 910 compound_name_arity(Goal, Name, Arity). 911callable_name_arity(Goal, Goal, 0) :- 912 atom(Goal). 913 914user_predicate_indicator(Module:PI, PI) :- 915 hidden_module(Module), 916 !. 917user_predicate_indicator(PI, PI). 918 (user):- !. 920hidden_module(system) :- !. 921hidden_module(M) :- 922 sub_atom(M, 0, _, _, $). 923 924current_definition(Proc, Prefix) --> 925 { pi_uhead(Proc, Head), 926 predicate_property(Head, file(File)), 927 predicate_property(Head, line_count(Line)) 928 }, 929 [ '~w'-[Prefix], url(File:Line), nl ]. 930current_definition(_, _) --> []. 931 932pi_uhead(Module:Name/Arity, Module:Head) :- 933 !, 934 atom(Module), atom(Name), integer(Arity), 935 functor(Head, Name, Arity). 936pi_uhead(Name/Arity, user:Head) :- 937 atom(Name), integer(Arity), 938 functor(Head, Name, Arity). 939 940qlf_recompile_reason(old) --> 941 !, 942 [ ' (out of date)'-[] ]. 943qlf_recompile_reason(_) --> 944 [ ' (incompatible with current Prolog version)'-[] ]. 945 946prolog_message(file_search(cache(Spec, _Cond), Path)) --> 947 [ 'File search: ~p --> ~p (cache)'-[Spec, Path] ]. 948prolog_message(file_search(found(Spec, Cond), Path)) --> 949 [ 'File search: ~p --> ~p OK ~p'-[Spec, Path, Cond] ]. 950prolog_message(file_search(tried(Spec, Cond), Path)) --> 951 [ 'File search: ~p --> ~p NO ~p'-[Spec, Path, Cond] ]. 952 953 /******************************* 954 * GC * 955 *******************************/ 956 957prolog_message(agc(start)) --> 958 thread_context, 959 [ 'AGC: ', flush ]. 960prolog_message(agc(done(Collected, Remaining, Time))) --> 961 [ at_same_line, 962 'reclaimed ~D atoms in ~3f sec. (remaining: ~D)'- 963 [Collected, Time, Remaining] 964 ]. 965prolog_message(cgc(start)) --> 966 thread_context, 967 [ 'CGC: ', flush ]. 968prolog_message(cgc(done(CollectedClauses, _CollectedBytes, 969 RemainingBytes, Time))) --> 970 [ at_same_line, 971 'reclaimed ~D clauses in ~3f sec. (pending: ~D bytes)'- 972 [CollectedClauses, Time, RemainingBytes] 973 ]. 974 975 /******************************* 976 * STACK OVERFLOW * 977 *******************************/ 978 979out_of_stack(Context) --> 980 { human_stack_size(Context.localused, Local), 981 human_stack_size(Context.globalused, Global), 982 human_stack_size(Context.trailused, Trail), 983 human_stack_size(Context.stack_limit, Limit), 984 LCO is (100*(Context.depth - Context.environments))/Context.depth 985 }, 986 [ 'Stack limit (~s) exceeded'-[Limit], nl, 987 ' Stack sizes: local: ~s, global: ~s, trail: ~s'-[Local,Global,Trail], nl, 988 ' Stack depth: ~D, last-call: ~0f%, Choice points: ~D'- 989 [Context.depth, LCO, Context.choicepoints], nl 990 ], 991 overflow_reason(Context, Resolve), 992 resolve_overflow(Resolve). 993 994human_stack_size(Size, String) :- 995 Size < 100, 996 format(string(String), '~dKb', [Size]). 997human_stack_size(Size, String) :- 998 Size < 100 000, 999 Value is Size / 1024, 1000 format(string(String), '~1fMb', [Value]). 1001human_stack_size(Size, String) :- 1002 Value is Size / (1024*1024), 1003 format(string(String), '~1fGb', [Value]). 1004 1005overflow_reason(Context, fix) --> 1006 show_non_termination(Context), 1007 !. 1008overflow_reason(Context, enlarge) --> 1009 { Stack = Context.get(stack) }, 1010 !, 1011 [ ' In:'-[], nl ], 1012 stack(Stack). 1013overflow_reason(_Context, enlarge) --> 1014 [ ' Insufficient global stack'-[] ]. 1015 1016show_non_termination(Context) --> 1017 ( { Stack = Context.get(cycle) } 1018 -> [ ' Probable infinite recursion (cycle):'-[], nl ] 1019 ; { Stack = Context.get(non_terminating) } 1020 -> [ ' Possible non-terminating recursion:'-[], nl ] 1021 ), 1022 stack(Stack). 1023 1024stack([]) --> []. 1025stack([frame(Depth, M:Goal, _)|T]) --> 1026 [ ' [~D] ~q:'-[Depth, M] ], 1027 stack_goal(Goal), 1028 [ nl ], 1029 stack(T). 1030 1031stack_goal(Goal) --> 1032 { compound(Goal), 1033 !, 1034 compound_name_arity(Goal, Name, Arity) 1035 }, 1036 [ '~q('-[Name] ], 1037 stack_goal_args(1, Arity, Goal), 1038 [ ')'-[] ]. 1039stack_goal(Goal) --> 1040 [ '~q'-[Goal] ]. 1041 1042stack_goal_args(I, Arity, Goal) --> 1043 { I =< Arity, 1044 !, 1045 arg(I, Goal, A), 1046 I2 is I + 1 1047 }, 1048 stack_goal_arg(A), 1049 ( { I2 =< Arity } 1050 -> [ ', '-[] ], 1051 stack_goal_args(I2, Arity, Goal) 1052 ; [] 1053 ). 1054stack_goal_args(_, _, _) --> 1055 []. 1056 1057stack_goal_arg(A) --> 1058 { nonvar(A), 1059 A = [Len|T], 1060 ! 1061 }, 1062 ( {Len == cyclic_term} 1063 -> [ '[cyclic list]'-[] ] 1064 ; {T == []} 1065 -> [ '[length:~D]'-[Len] ] 1066 ; [ '[length:~D|~p]'-[Len, T] ] 1067 ). 1068stack_goal_arg(A) --> 1069 { nonvar(A), 1070 A = _/_, 1071 ! 1072 }, 1073 [ '<compound ~p>'-[A] ]. 1074stack_goal_arg(A) --> 1075 [ '~p'-[A] ]. 1076 1077resolve_overflow(fix) --> 1078 []. 1079resolve_overflow(enlarge) --> 1080 { current_prolog_flag(stack_limit, LimitBytes), 1081 NewLimit is LimitBytes * 2 1082 }, 1083 [ nl, 1084 'Use the --stack_limit=size[KMG] command line option or'-[], nl, 1085 '?- set_prolog_flag(stack_limit, ~I). to double the limit.'-[NewLimit] 1086 ].
1093out_of_c_stack --> 1094 { statistics(c_stack, Limit), Limit > 0 }, 1095 !, 1096 [ 'C-stack limit (~D bytes) exceeded.'-[Limit], nl ], 1097 resolve_c_stack_overflow(Limit). 1098out_of_c_stack --> 1099 { statistics(c_stack, Limit), Limit > 0 }, 1100 [ 'C-stack limit exceeded.'-[Limit], nl ], 1101 resolve_c_stack_overflow(Limit). 1102 1103resolve_c_stack_overflow(_Limit) --> 1104 { thread_self(main) }, 1105 [ 'Use the shell command ' ], code('~w', 'ulimit -s size'), 1106 [ ' to enlarge the limit.' ]. 1107resolve_c_stack_overflow(_Limit) --> 1108 [ 'Use the ' ], code('~w', 'c_stack(KBytes)'), 1109 [ ' option of '], code(thread_create/3), [' to enlarge the limit.' ]. 1110 1111 1112 /******************************* 1113 * MAKE/AUTOLOAD * 1114 *******************************/ 1115 1116prolog_message(make(reload(Files))) --> 1117 { length(Files, N) 1118 }, 1119 [ 'Make: reloading ~D files'-[N] ]. 1120prolog_message(make(done(_Files))) --> 1121 [ 'Make: finished' ]. 1122prolog_message(make(library_index(Dir))) --> 1123 [ 'Updating index for library ~w'-[Dir] ]. 1124prolog_message(autoload(Pred, File)) --> 1125 thread_context, 1126 [ 'autoloading ~p from ~w'-[Pred, File] ]. 1127prolog_message(autoload(read_index(Dir))) --> 1128 [ 'Loading autoload index for ~w'-[Dir] ]. 1129prolog_message(autoload(disabled(Loaded))) --> 1130 [ 'Disabled autoloading (loaded ~D files)'-[Loaded] ]. 1131prolog_message(autoload(already_defined(PI, From))) --> 1132 code(PI), 1133 ( { '$pi_head'(PI, Head), 1134 predicate_property(Head, built_in) 1135 } 1136 -> [' is a built-in predicate'] 1137 ; [ ' is already imported from module ' ], 1138 code(From) 1139 ). 1140 1141swi_message(autoload(Msg)) --> 1142 [ nl, ' ' ], 1143 autoload_message(Msg). 1144 1145autoload_message(not_exported(PI, Spec, _FullFile, _Exports)) --> 1146 [ ansi(code, '~w', [Spec]), 1147 ' does not export ', 1148 ansi(code, '~p', [PI]) 1149 ]. 1150autoload_message(no_file(Spec)) --> 1151 [ ansi(code, '~p', [Spec]), ': No such file' ]. 1152 1153 1154 /******************************* 1155 * COMPILER WARNINGS * 1156 *******************************/ 1157 1158% print warnings about dubious code raised by the compiler. 1159% TBD: pass in PC to produce exact error locations. 1160 1161prolog_message(compiler_warnings(Clause, Warnings0)) --> 1162 { print_goal_options(DefOptions), 1163 ( prolog_load_context(variable_names, VarNames) 1164 -> warnings_with_named_vars(Warnings0, VarNames, Warnings), 1165 Options = [variable_names(VarNames)|DefOptions] 1166 ; Options = DefOptions, 1167 Warnings = Warnings0 1168 ) 1169 }, 1170 compiler_warnings(Warnings, Clause, Options). 1171 1172warnings_with_named_vars([], _, []). 1173warnings_with_named_vars([H|T0], VarNames, [H|T]) :- 1174 term_variables(H, Vars), 1175 '$member'(V1, Vars), 1176 '$member'(_=V2, VarNames), 1177 V1 == V2, 1178 !, 1179 warnings_with_named_vars(T0, VarNames, T). 1180warnings_with_named_vars([_|T0], VarNames, T) :- 1181 warnings_with_named_vars(T0, VarNames, T). 1182 1183 1184compiler_warnings([], _, _) --> []. 1185compiler_warnings([H|T], Clause, Options) --> 1186 ( compiler_warning(H, Clause, Options) 1187 -> [] 1188 ; [ 'Unknown compiler warning: ~W'-[H,Options] ] 1189 ), 1190 ( {T==[]} 1191 -> [] 1192 ; [nl] 1193 ), 1194 compiler_warnings(T, Clause, Options). 1195 1196compiler_warning(eq_vv(A,B), _Clause, Options) --> 1197 ( { A == B } 1198 -> [ 'Test is always true: ~W'-[A==B, Options] ] 1199 ; [ 'Test is always false: ~W'-[A==B, Options] ] 1200 ). 1201compiler_warning(eq_singleton(A,B), _Clause, Options) --> 1202 [ 'Test is always false: ~W'-[A==B, Options] ]. 1203compiler_warning(neq_vv(A,B), _Clause, Options) --> 1204 ( { A \== B } 1205 -> [ 'Test is always true: ~W'-[A\==B, Options] ] 1206 ; [ 'Test is always false: ~W'-[A\==B, Options] ] 1207 ). 1208compiler_warning(neq_singleton(A,B), _Clause, Options) --> 1209 [ 'Test is always true: ~W'-[A\==B, Options] ]. 1210compiler_warning(unify_singleton(A,B), _Clause, Options) --> 1211 [ 'Unified variable is not used: ~W'-[A=B, Options] ]. 1212compiler_warning(always(Bool, Pred, Arg), _Clause, Options) --> 1213 { Goal =.. [Pred,Arg] }, 1214 [ 'Test is always ~w: ~W'-[Bool, Goal, Options] ]. 1215compiler_warning(unbalanced_var(V), _Clause, Options) --> 1216 [ 'Variable not introduced in all branches: ~W'-[V, Options] ]. 1217compiler_warning(branch_singleton(V), _Clause, Options) --> 1218 [ 'Singleton variable in branch: ~W'-[V, Options] ]. 1219compiler_warning(negation_singleton(V), _Clause, Options) --> 1220 [ 'Singleton variable in \\+: ~W'-[V, Options] ]. 1221compiler_warning(multiton(V), _Clause, Options) --> 1222 [ 'Singleton-marked variable appears more than once: ~W'-[V, Options] ]. 1223 1224print_goal_options( 1225 [ quoted(true), 1226 portray(true) 1227 ]). 1228 1229 1230 /******************************* 1231 * TOPLEVEL MESSAGES * 1232 *******************************/ 1233 1234prolog_message(version) --> 1235 { current_prolog_flag(version_git, Version) }, 1236 !, 1237 [ '~w'-[Version] ]. 1238prolog_message(version) --> 1239 { current_prolog_flag(version_data, swi(Major,Minor,Patch,Options)) 1240 }, 1241 ( { memberchk(tag(Tag), Options) } 1242 -> [ '~w.~w.~w-~w'-[Major, Minor, Patch, Tag] ] 1243 ; [ '~w.~w.~w'-[Major, Minor, Patch] ] 1244 ). 1245prolog_message(address_bits) --> 1246 { current_prolog_flag(address_bits, Bits) 1247 }, 1248 !, 1249 [ '~d bits, '-[Bits] ]. 1250prolog_message(threads) --> 1251 { current_prolog_flag(threads, true) 1252 }, 1253 !, 1254 [ 'threaded, ' ]. 1255prolog_message(threads) --> 1256 []. 1257prolog_message(copyright) --> 1258 [ 'SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.', nl, 1259 'Please run ?- license. for legal details.' 1260 ]. 1261prolog_message(documentaton) --> 1262 [ 'For online help and background, visit https://www.swi-prolog.org', nl, 1263 'For built-in help, use ?- help(Topic). or ?- apropos(Word).' 1264 ]. 1265prolog_message(about) --> 1266 [ 'SWI-Prolog version (' ], 1267 prolog_message(threads), 1268 prolog_message(address_bits), 1269 ['version ' ], 1270 prolog_message(version), 1271 [ ')', nl ], 1272 prolog_message(copyright). 1273prolog_message(halt) --> 1274 [ 'halt' ]. 1275prolog_message(break(begin, Level)) --> 1276 [ 'Break level ~d'-[Level] ]. 1277prolog_message(break(end, Level)) --> 1278 [ 'Exit break level ~d'-[Level] ]. 1279prolog_message(var_query(_)) --> 1280 [ '... 1,000,000 ............ 10,000,000 years later', nl, nl, 1281 '~t~8|>> 42 << (last release gives the question)' 1282 ]. 1283prolog_message(close_on_abort(Stream)) --> 1284 [ 'Abort: closed stream ~p'-[Stream] ]. 1285prolog_message(cancel_halt(Reason)) --> 1286 [ 'Halt cancelled: ~p'-[Reason] ]. 1287prolog_message(on_error(halt(Status))) --> 1288 { statistics(errors, Errors), 1289 statistics(warnings, Warnings) 1290 }, 1291 [ 'Halting with status ~w due to ~D errors and ~D warnings'- 1292 [Status, Errors, Warnings] ]. 1293 1294prolog_message(query(QueryResult)) --> 1295 query_result(QueryResult). 1296 1297query_result(no) --> % failure 1298 [ ansi(truth(false), 'false.', []) ], 1299 extra_line. 1300query_result(yes(true, [])) --> % prompt_alternatives_on: groundness 1301 !, 1302 [ ansi(truth(true), 'true.', []) ], 1303 extra_line. 1304query_result(yes(Delays, Residuals)) --> 1305 result([], Delays, Residuals), 1306 extra_line. 1307query_result(done) --> % user typed <CR> 1308 extra_line. 1309query_result(yes(Bindings, Delays, Residuals)) --> 1310 result(Bindings, Delays, Residuals), 1311 prompt(yes, Bindings, Delays, Residuals). 1312query_result(more(Bindings, Delays, Residuals)) --> 1313 result(Bindings, Delays, Residuals), 1314 prompt(more, Bindings, Delays, Residuals). 1315query_result(help) --> 1316 [ ansi(bold, ' Possible actions:', []), nl, 1317 ' ; (n,r,space,TAB): redo | t: trace&redo'-[], nl, 1318 ' *: show choicepoint | c (a,RET): stop'-[], nl, 1319 ' w: write | p: print'-[], nl, 1320 ' b: break | h (?): help'-[], 1321 nl, nl 1322 ]. 1323query_result(action) --> 1324 [ 'Action? '-[], flush ]. 1325query_result(confirm) --> 1326 [ 'Please answer \'y\' or \'n\'? '-[], flush ]. 1327query_result(eof) --> 1328 [ nl ]. 1329query_result(toplevel_open_line) --> 1330 []. 1331 1332prompt(Answer, [], true, []-[]) --> 1333 !, 1334 prompt(Answer, empty). 1335prompt(Answer, _, _, _) --> 1336 !, 1337 prompt(Answer, non_empty). 1338 1339prompt(yes, empty) --> 1340 !, 1341 [ ansi(truth(true), 'true.', []) ], 1342 extra_line. 1343prompt(yes, _) --> 1344 !, 1345 [ full_stop ], 1346 extra_line. 1347prompt(more, empty) --> 1348 !, 1349 [ ansi(truth(true), 'true ', []), flush ]. 1350prompt(more, _) --> 1351 !, 1352 [ ' '-[], flush ]. 1353 1354result(Bindings, Delays, Residuals) --> 1355 { current_prolog_flag(answer_write_options, Options0), 1356 Options = [partial(true)|Options0], 1357 GOptions = [priority(999)|Options0] 1358 }, 1359 wfs_residual_program(Delays, GOptions), 1360 bindings(Bindings, [priority(699)|Options]), 1361 ( {Residuals == []-[]} 1362 -> bind_delays_sep(Bindings, Delays), 1363 delays(Delays, GOptions) 1364 ; bind_res_sep(Bindings, Residuals), 1365 residuals(Residuals, GOptions), 1366 ( {Delays == true} 1367 -> [] 1368 ; [','-[], nl], 1369 delays(Delays, GOptions) 1370 ) 1371 ). 1372 1373bindings([], _) --> 1374 []. 1375bindings([binding(Names,Skel,Subst)|T], Options) --> 1376 { '$last'(Names, Name) }, 1377 var_names(Names), value(Name, Skel, Subst, Options), 1378 ( { T \== [] } 1379 -> [ ','-[], nl ], 1380 bindings(T, Options) 1381 ; [] 1382 ). 1383 1384var_names([Name]) --> 1385 !, 1386 [ '~w = '-[Name] ]. 1387var_names([Name1,Name2|T]) --> 1388 !, 1389 [ '~w = ~w, '-[Name1, Name2] ], 1390 var_names([Name2|T]). 1391 1392 1393value(Name, Skel, Subst, Options) --> 1394 ( { var(Skel), Subst = [Skel=S] } 1395 -> { Skel = '$VAR'(Name) }, 1396 [ '~W'-[S, Options] ] 1397 ; [ '~W'-[Skel, Options] ], 1398 substitution(Subst, Options) 1399 ). 1400 1401substitution([], _) --> !. 1402substitution([N=V|T], Options) --> 1403 [ ', ', ansi(comment, '% where', []), nl, 1404 ' ~w = ~W'-[N,V,Options] ], 1405 substitutions(T, Options). 1406 1407substitutions([], _) --> []. 1408substitutions([N=V|T], Options) --> 1409 [ ','-[], nl, ' ~w = ~W'-[N,V,Options] ], 1410 substitutions(T, Options). 1411 1412 1413residuals(Normal-Hidden, Options) --> 1414 residuals1(Normal, Options), 1415 bind_res_sep(Normal, Hidden), 1416 ( {Hidden == []} 1417 -> [] 1418 ; [ansi(comment, '% with pending residual goals', []), nl] 1419 ), 1420 residuals1(Hidden, Options). 1421 1422residuals1([], _) --> 1423 []. 1424residuals1([G|Gs], Options) --> 1425 ( { Gs \== [] } 1426 -> [ '~W,'-[G, Options], nl ], 1427 residuals1(Gs, Options) 1428 ; [ '~W'-[G, Options] ] 1429 ). 1430 1431wfs_residual_program(true, _Options) --> 1432 !. 1433wfs_residual_program(Goal, _Options) --> 1434 { current_prolog_flag(toplevel_list_wfs_residual_program, true), 1435 '$current_typein_module'(TypeIn), 1436 ( current_predicate(delays_residual_program/2) 1437 -> true 1438 ; use_module(library(wfs), [delays_residual_program/2]) 1439 ), 1440 delays_residual_program(TypeIn:Goal, TypeIn:Program), 1441 Program \== [] 1442 }, 1443 !, 1444 [ ansi(comment, '% WFS residual program', []), nl ], 1445 [ ansi(wfs(residual_program), '~@', ['$messages':list_clauses(Program)]) ]. 1446wfs_residual_program(_, _) --> []. 1447 1448delays(true, _Options) --> 1449 !. 1450delays(Goal, Options) --> 1451 { current_prolog_flag(toplevel_list_wfs_residual_program, true) 1452 }, 1453 !, 1454 [ ansi(truth(undefined), '~W', [Goal, Options]) ]. 1455delays(_, _Options) --> 1456 [ ansi(truth(undefined), undefined, []) ]. 1457 1458:- public list_clauses/1. 1459 1460list_clauses([]). 1461list_clauses([H|T]) :- 1462 ( system_undefined(H) 1463 -> true 1464 ; portray_clause(user_output, H, [indent(4)]) 1465 ), 1466 list_clauses(T). 1467 1468system_undefined((undefined :- tnot(undefined))). 1469system_undefined((answer_count_restraint :- tnot(answer_count_restraint))). 1470system_undefined((radial_restraint :- tnot(radial_restraint))). 1471 1472bind_res_sep(_, []) --> !. 1473bind_res_sep(_, []-[]) --> !. 1474bind_res_sep([], _) --> !. 1475bind_res_sep(_, _) --> [','-[], nl]. 1476 1477bind_delays_sep([], _) --> !. 1478bind_delays_sep(_, true) --> !. 1479bind_delays_sep(_, _) --> [','-[], nl]. 1480 1481extra_line --> 1482 { current_prolog_flag(toplevel_extra_white_line, true) }, 1483 !, 1484 ['~N'-[]]. 1485extra_line --> 1486 []. 1487 1488prolog_message(if_tty(Message)) --> 1489 ( {current_prolog_flag(tty_control, true)} 1490 -> [ at_same_line | Message ] 1491 ; [] 1492 ). 1493prolog_message(halt(Reason)) --> 1494 [ '~w: halt'-[Reason] ]. 1495prolog_message(no_action(Char)) --> 1496 [ 'Unknown action: ~c (h for help)'-[Char], nl ]. 1497 1498prolog_message(history(help(Show, Help))) --> 1499 [ 'History Commands:', nl, 1500 ' !!. Repeat last query', nl, 1501 ' !nr. Repeat query numbered <nr>', nl, 1502 ' !str. Repeat last query starting with <str>', nl, 1503 ' !?str. Repeat last query holding <str>', nl, 1504 ' ^old^new. Substitute <old> into <new> of last query', nl, 1505 ' !nr^old^new. Substitute in query numbered <nr>', nl, 1506 ' !str^old^new. Substitute in query starting with <str>', nl, 1507 ' !?str^old^new. Substitute in query holding <str>', nl, 1508 ' ~w.~21|Show history list'-[Show], nl, 1509 ' ~w.~21|Show this list'-[Help], nl, nl 1510 ]. 1511prolog_message(history(no_event)) --> 1512 [ '! No such event' ]. 1513prolog_message(history(bad_substitution)) --> 1514 [ '! Bad substitution' ]. 1515prolog_message(history(expanded(Event))) --> 1516 [ '~w.'-[Event] ]. 1517prolog_message(history(history(Events))) --> 1518 history_events(Events). 1519 1520history_events([]) --> 1521 []. 1522history_events([Nr/Event|T]) --> 1523 [ '~t~w ~8|~W~W'-[ Nr, 1524 Event, [partial(true)], 1525 '.', [partial(true)] 1526 ], 1527 nl 1528 ], 1529 history_events(T).
welcome
message to print information registered
using version/1.1537user_version_messages([]) --> []. 1538user_version_messages([H|T]) --> 1539 user_version_message(H), 1540 user_version_messages(T).
1544user_version_message(Term) --> 1545 translate_message(Term), !, [nl]. 1546user_version_message(Atom) --> 1547 [ '~w'-[Atom], nl ]. 1548 1549 1550 /******************************* 1551 * DEBUGGER MESSAGES * 1552 *******************************/ 1553 1554prolog_message(spy(Head)) --> 1555 { goal_to_predicate_indicator(Head, Pred) 1556 }, 1557 [ 'Spy point on ~p'-[Pred] ]. 1558prolog_message(nospy(Head)) --> 1559 { goal_to_predicate_indicator(Head, Pred) 1560 }, 1561 [ 'Spy point removed from ~p'-[Pred] ]. 1562prolog_message(trace_mode(OnOff)) --> 1563 [ 'Trace mode switched to ~w'-[OnOff] ]. 1564prolog_message(debug_mode(OnOff)) --> 1565 [ 'Debug mode switched to ~w'-[OnOff] ]. 1566prolog_message(debugging(OnOff)) --> 1567 [ 'Debug mode is ~w'-[OnOff] ]. 1568prolog_message(spying([])) --> 1569 !, 1570 [ 'No spy points' ]. 1571prolog_message(spying(Heads)) --> 1572 [ 'Spy points (see spy/1) on:', nl ], 1573 predicate_list(Heads). 1574prolog_message(trace(Head, [])) --> 1575 !, 1576 { goal_to_predicate_indicator(Head, Pred) 1577 }, 1578 [ ' ~p: Not tracing'-[Pred], nl]. 1579prolog_message(trace(Head, Ports)) --> 1580 { goal_to_predicate_indicator(Head, Pred) 1581 }, 1582 [ ' ~p: ~w'-[Pred, Ports], nl]. 1583prolog_message(tracing([])) --> 1584 !, 1585 [ 'No traced predicates (see trace/1)' ]. 1586prolog_message(tracing(Heads)) --> 1587 [ 'Trace points (see trace/1) on:', nl ], 1588 tracing_list(Heads). 1589 1590predicate_list([]) --> % TBD: Share with dwim, etc. 1591 []. 1592predicate_list([H|T]) --> 1593 { goal_to_predicate_indicator(H, Pred) 1594 }, 1595 [ ' ~p'-[Pred], nl], 1596 predicate_list(T). 1597 1598tracing_list([]) --> 1599 []. 1600tracing_list([trace(Head, Ports)|T]) --> 1601 translate_message(trace(Head, Ports)), 1602 tracing_list(T). 1603 1604prolog_message(frame(Frame, backtrace, _PC)) --> 1605 !, 1606 { prolog_frame_attribute(Frame, level, Level) 1607 }, 1608 [ ansi(frame(level), '~t[~D] ~10|', [Level]) ], 1609 frame_context(Frame), 1610 frame_goal(Frame). 1611prolog_message(frame(Frame, choice, PC)) --> 1612 !, 1613 prolog_message(frame(Frame, backtrace, PC)). 1614prolog_message(frame(_, cut_call, _)) --> !, []. 1615prolog_message(frame(Goal, trace(Port))) --> 1616 !, 1617 thread_context, 1618 [ ' T ' ], 1619 port(Port), 1620 goal(Goal). 1621prolog_message(frame(Goal, trace(Port, Id))) --> 1622 !, 1623 thread_context, 1624 [ ' T ' ], 1625 port(Port, Id), 1626 goal(Goal). 1627prolog_message(frame(Frame, Port, _PC)) --> 1628 frame_flags(Frame), 1629 port(Port), 1630 frame_level(Frame), 1631 frame_context(Frame), 1632 frame_depth_limit(Port, Frame), 1633 frame_goal(Frame), 1634 [ flush ]. 1635 1636frame_goal(Frame) --> 1637 { prolog_frame_attribute(Frame, goal, Goal) 1638 }, 1639 goal(Goal). 1640 1641goal(Goal0) --> 1642 { clean_goal(Goal0, Goal), 1643 current_prolog_flag(debugger_write_options, Options) 1644 }, 1645 [ '~W'-[Goal, Options] ]. 1646 1647frame_level(Frame) --> 1648 { prolog_frame_attribute(Frame, level, Level) 1649 }, 1650 [ '(~D) '-[Level] ]. 1651 1652frame_context(Frame) --> 1653 ( { current_prolog_flag(debugger_show_context, true), 1654 prolog_frame_attribute(Frame, context_module, Context) 1655 } 1656 -> [ '[~w] '-[Context] ] 1657 ; [] 1658 ). 1659 1660frame_depth_limit(fail, Frame) --> 1661 { prolog_frame_attribute(Frame, depth_limit_exceeded, true) 1662 }, 1663 !, 1664 [ '[depth-limit exceeded] ' ]. 1665frame_depth_limit(_, _) --> 1666 []. 1667 1668frame_flags(Frame) --> 1669 { prolog_frame_attribute(Frame, goal, Goal), 1670 ( predicate_property(Goal, transparent) 1671 -> T = '^' 1672 ; T = ' ' 1673 ), 1674 ( predicate_property(Goal, spying) 1675 -> S = '*' 1676 ; S = ' ' 1677 ) 1678 }, 1679 [ '~w~w '-[T, S] ]. 1680 1681% trace/1,2 context handling 1682port(Port, _Id-Level) --> 1683 [ '[~d] '-Level ], 1684 port(Port). 1685 1686port(Port) --> 1687 { port_name(Port, Name) 1688 }, 1689 !, 1690 [ ansi(port(Port), '~w: ', [Name]) ]. 1691 1692port_name(call, 'Call'). 1693port_name(exit, 'Exit'). 1694port_name(fail, 'Fail'). 1695port_name(redo, 'Redo'). 1696port_name(unify, 'Unify'). 1697port_name(exception, 'Exception'). 1698 1699clean_goal(M:Goal, Goal) :- 1700 hidden_module(M), 1701 !. 1702clean_goal(M:Goal, Goal) :- 1703 predicate_property(M:Goal, built_in), 1704 !. 1705clean_goal(Goal, Goal). 1706 1707 1708 /******************************* 1709 * COMPATIBILITY * 1710 *******************************/ 1711 1712prolog_message(compatibility(renamed(Old, New))) --> 1713 [ 'The predicate ~p has been renamed to ~p.'-[Old, New], nl, 1714 'Please update your sources for compatibility with future versions.' 1715 ]. 1716 1717 1718 /******************************* 1719 * THREADS * 1720 *******************************/ 1721 1722prolog_message(abnormal_thread_completion(Goal, exception(Ex))) --> 1723 !, 1724 [ 'Thread running "~p" died on exception: '-[Goal] ], 1725 translate_message(Ex). 1726prolog_message(abnormal_thread_completion(Goal, fail)) --> 1727 [ 'Thread running "~p" died due to failure'-[Goal] ]. 1728prolog_message(threads_not_died(Running)) --> 1729 [ 'The following threads wouldn\'t die: ~p'-[Running] ]. 1730 1731 1732 /******************************* 1733 * PACKS * 1734 *******************************/ 1735 1736prolog_message(pack(attached(Pack, BaseDir))) --> 1737 [ 'Attached package ~w at ~q'-[Pack, BaseDir] ]. 1738prolog_message(pack(duplicate(Entry, OldDir, Dir))) --> 1739 [ 'Package ~w already attached at ~q.'-[Entry,OldDir], nl, 1740 '\tIgnoring version from ~q'- [Dir] 1741 ]. 1742prolog_message(pack(no_arch(Entry, Arch))) --> 1743 [ 'Package ~w: no binary for architecture ~w'-[Entry, Arch] ]. 1744 1745 /******************************* 1746 * MISC * 1747 *******************************/ 1748 1749prolog_message(null_byte_in_path(Component)) --> 1750 [ '0-byte in PATH component: ~p (skipped directory)'-[Component] ]. 1751prolog_message(invalid_tmp_dir(Dir, Reason)) --> 1752 [ 'Cannot use ~p as temporary file directory: ~w'-[Dir, Reason] ]. 1753prolog_message(ambiguous_stream_pair(Pair)) --> 1754 [ 'Ambiguous operation on stream pair ~p'-[Pair] ]. 1755prolog_message(backcomp(init_file_moved(FoundFile))) --> 1756 { absolute_file_name(app_config('init.pl'), InitFile, 1757 [ file_errors(fail) 1758 ]) 1759 }, 1760 [ 'The location of the config file has moved'-[], nl, 1761 ' from "~w"'-[FoundFile], nl, 1762 ' to "~w"'-[InitFile], nl, 1763 ' See https://www.swi-prolog.org/modified/config-files.html'-[] 1764 ]. 1765 1766 /******************************* 1767 * DEPRECATED * 1768 *******************************/ 1769 1770deprecated(set_prolog_stack(_Stack,limit)) --> 1771 [ 'set_prolog_stack/2: limit(Size) sets the combined limit.'-[], nl, 1772 'See https://www.swi-prolog.org/changes/stack-limit.html' 1773 ]. 1774 1775 /******************************* 1776 * TRIPWIRES * 1777 *******************************/ 1778 1779tripwire_message(Wire, Context) --> 1780 [ 'Trapped tripwire ~w for '-[Wire] ], 1781 tripwire_context(Wire, Context). 1782 1783tripwire_context(_, ATrie) --> 1784 { '$is_answer_trie'(ATrie, _), 1785 !, 1786 '$tabling':atrie_goal(ATrie, QGoal), 1787 user_predicate_indicator(QGoal, Goal) 1788 }, 1789 [ '~p'-[Goal] ]. 1790tripwire_context(_, Ctx) --> 1791 [ '~p'-[Ctx] ]. 1792 1793 1794 /******************************* 1795 * INTERNATIONALIZATION * 1796 *******************************/ 1797 1798:- create_prolog_flag(message_language, default, []).
nl_BE
) and ends with en
.1805message_lang(Lang) :- 1806 current_message_lang(Lang0), 1807 ( Lang0 == en 1808 -> Lang = en 1809 ; sub_atom(Lang0, 0, _, _, en_) 1810 -> longest_id(Lang0, Lang) 1811 ; ( longest_id(Lang0, Lang) 1812 ; Lang = en 1813 ) 1814 ). 1815 1816longest_id(Lang, Id) :- 1817 split_string(Lang, "_-", "", [H|Components]), 1818 longest_prefix(Components, Taken), 1819 atomic_list_concat([H|Taken], '_', Id). 1820 1821longest_prefix([H|T0], [H|T]) :- 1822 longest_prefix(T0, T). 1823longest_prefix(_, []).
1829current_message_lang(Lang) :- 1830 ( current_prolog_flag(message_language, Lang0), 1831 Lang0 \== default 1832 -> Lang = Lang0 1833 ; os_user_lang(Lang0) 1834 -> clean_encoding(Lang0, Lang1), 1835 set_prolog_flag(message_language, Lang1), 1836 Lang = Lang1 1837 ; Lang = en 1838 ). 1839 1840os_user_lang(Lang) :- 1841 current_prolog_flag(windows, true), 1842 win_get_user_preferred_ui_languages(name, [Lang|_]). 1843os_user_lang(Lang) :- 1844 catch(setlocale(messages, _, ''), _, fail), 1845 setlocale(messages, Lang, Lang). 1846os_user_lang(Lang) :- 1847 getenv('LANG', Lang). 1848 1849 1850clean_encoding(Lang0, Lang) :- 1851 ( sub_atom(Lang0, A, _, _, '.') 1852 -> sub_atom(Lang0, 0, A, _, Lang) 1853 ; Lang = Lang0 1854 ). 1855 1856 /******************************* 1857 * PRIMITIVES * 1858 *******************************/ 1859 1860code(Term) --> 1861 code('~p', Term). 1862 1863code(Format, Term) --> 1864 [ ansi(code, Format, [Term]) ]. 1865 1866 1867 /******************************* 1868 * DEFAULT THEME * 1869 *******************************/ 1870 1871:- public default_theme/2. 1872 1873default_theme(var, [fg(red)]). 1874default_theme(code, [fg(blue)]). 1875default_theme(comment, [fg(green)]). 1876default_theme(warning, [fg(red)]). 1877default_theme(error, [bold, fg(red)]). 1878default_theme(truth(false), [bold, fg(red)]). 1879default_theme(truth(true), [bold]). 1880default_theme(truth(undefined), [bold, fg(cyan)]). 1881default_theme(wfs(residual_program), [fg(cyan)]). 1882default_theme(frame(level), [bold]). 1883default_theme(port(call), [bold, fg(green)]). 1884default_theme(port(exit), [bold, fg(green)]). 1885default_theme(port(fail), [bold, fg(red)]). 1886default_theme(port(redo), [bold, fg(yellow)]). 1887default_theme(port(unify), [bold, fg(blue)]). 1888default_theme(port(exception), [bold, fg(magenta)]). 1889default_theme(message(informational), [fg(green)]). 1890default_theme(message(information), [fg(green)]). 1891default_theme(message(debug(_)), [fg(blue)]). 1892default_theme(message(Level), Attrs) :- 1893 nonvar(Level), 1894 default_theme(Level, Attrs). 1895 1896 1897 /******************************* 1898 * PRINTING MESSAGES * 1899 *******************************/ 1900 1901:- multifile 1902 user:message_hook/3, 1903 prolog:message_prefix_hook/2. 1904:- dynamic 1905 user:message_hook/3, 1906 prolog:message_prefix_hook/2. 1907:- thread_local 1908 user:thread_message_hook/3. 1909:- '$hide'((push_msg/1,pop_msg/0)).
1916print_message(Level, _Term) :- 1917 msg_property(Level, stream(S)), 1918 stream_property(S, error(true)), 1919 !. 1920print_message(Level, Term) :- 1921 setup_call_cleanup( 1922 push_msg(Term, Stack), 1923 ignore(print_message_guarded(Level, Term)), 1924 pop_msg(Stack)), 1925 !. 1926print_message(Level, Term) :- 1927 ( Level \== silent 1928 -> format(user_error, 'Recursive ~w message: ~q~n', [Level, Term]), 1929 backtrace(20) 1930 ; true 1931 ). 1932 1933push_msg(Term, Messages) :- 1934 nb_current('$inprint_message', Messages), 1935 !, 1936 \+ ( '$member'(Msg, Messages), 1937 Msg =@= Term 1938 ), 1939 Stack = [Term|Messages], 1940 b_setval('$inprint_message', Stack). 1941push_msg(Term, []) :- 1942 b_setval('$inprint_message', [Term]). 1943 1944pop_msg(Stack) :- 1945 nb_delete('$inprint_message'), % delete history 1946 b_setval('$inprint_message', Stack). 1947 1948print_message_guarded(Level, Term) :- 1949 ( must_print(Level, Term) 1950 -> ( translate_message(Term, Lines, []) 1951 -> ( nonvar(Term), 1952 ( notrace(user:thread_message_hook(Term, Level, Lines)) 1953 -> true 1954 ; notrace(user:message_hook(Term, Level, Lines)) 1955 ) 1956 -> true 1957 ; '$inc_message_count'(Level), 1958 print_system_message(Term, Level, Lines), 1959 maybe_halt_on_error(Level) 1960 ) 1961 ) 1962 ; true 1963 ). 1964 1965maybe_halt_on_error(error) :- 1966 current_prolog_flag(on_error, halt), 1967 !, 1968 halt(1). 1969maybe_halt_on_error(warning) :- 1970 current_prolog_flag(on_warning, halt), 1971 !, 1972 halt(1). 1973maybe_halt_on_error(_).
1983print_system_message(_, silent, _) :- !. 1984print_system_message(_, informational, _) :- 1985 current_prolog_flag(verbose, silent), 1986 !. 1987print_system_message(_, banner, _) :- 1988 current_prolog_flag(verbose, silent), 1989 !. 1990print_system_message(_, _, []) :- !. 1991print_system_message(Term, Kind, Lines) :- 1992 catch(flush_output(user_output), _, true), % may not exist 1993 source_location(File, Line), 1994 Term \= error(syntax_error(_), _), 1995 msg_property(Kind, location_prefix(File:Line, LocPrefix, LinePrefix)), 1996 !, 1997 to_list(LocPrefix, LocPrefixL), 1998 insert_prefix(Lines, LinePrefix, Ctx, PrefixLines), 1999 '$append'([ [begin(Kind, Ctx)], 2000 LocPrefixL, 2001 [nl], 2002 PrefixLines, 2003 [end(Ctx)] 2004 ], 2005 AllLines), 2006 msg_property(Kind, stream(Stream)), 2007 ignore(stream_property(Stream, position(Pos))), 2008 print_message_lines(Stream, AllLines), 2009 ( \+ stream_property(Stream, position(Pos)), 2010 msg_property(Kind, wait(Wait)), 2011 Wait > 0 2012 -> sleep(Wait) 2013 ; true 2014 ). 2015print_system_message(_, Kind, Lines) :- 2016 msg_property(Kind, stream(Stream)), 2017 print_message_lines(Stream, kind(Kind), Lines). 2018 2019to_list(ListIn, List) :- 2020 is_list(ListIn), 2021 !, 2022 List = ListIn. 2023to_list(NonList, [NonList]). 2024 2025:- multifile 2026 user:message_property/2. 2027 2028msg_property(Kind, Property) :- 2029 notrace(user:message_property(Kind, Property)), 2030 !. 2031msg_property(Kind, prefix(Prefix)) :- 2032 msg_prefix(Kind, Prefix), 2033 !. 2034msg_property(_, prefix('~N')) :- !. 2035msg_property(query, stream(user_output)) :- !. 2036msg_property(_, stream(user_error)) :- !. 2037msg_property(error, tag('ERROR')). 2038msg_property(warning, tag('Warning')). 2039msg_property(Level, 2040 location_prefix(File:Line, 2041 ['~N~w: '-[Tag], url(File:Line), ':'], 2042 '~N~w: '-[Tag])) :- 2043 include_msg_location(Level), 2044 msg_property(Level, tag(Tag)). 2045msg_property(error, wait(0.1)) :- !. 2046 2047include_msg_location(warning). 2048include_msg_location(error). 2049 2050msg_prefix(debug(_), Prefix) :- 2051 msg_context('~N% ', Prefix). 2052msg_prefix(Level, Prefix) :- 2053 msg_property(Level, tag(Tag)), 2054 atomics_to_string(['~N', Tag, ': '], Prefix0), 2055 msg_context(Prefix0, Prefix). 2056msg_prefix(informational, '~N% '). 2057msg_prefix(information, '~N% ').
message_context
. Recognised context terms are:
time(Format)
In addition, the hook message_prefix_hook/2 is called that allows for additional context information.
2071msg_context(Prefix0, Prefix) :- 2072 current_prolog_flag(message_context, Context), 2073 is_list(Context), 2074 !, 2075 add_message_context(Context, Prefix0, Prefix). 2076msg_context(Prefix, Prefix). 2077 2078add_message_context([], Prefix, Prefix). 2079add_message_context([H|T], Prefix0, Prefix) :- 2080 ( add_message_context1(H, Prefix0, Prefix1) 2081 -> true 2082 ; Prefix1 = Prefix0 2083 ), 2084 add_message_context(T, Prefix1, Prefix). 2085 2086add_message_context1(Context, Prefix0, Prefix) :- 2087 prolog:message_prefix_hook(Context, Extra), 2088 atomics_to_string([Prefix0, Extra, ' '], Prefix). 2089add_message_context1(time, Prefix0, Prefix) :- 2090 get_time(Now), 2091 format_time(string(S), '%T.%3f ', Now), 2092 string_concat(Prefix0, S, Prefix). 2093add_message_context1(time(Format), Prefix0, Prefix) :- 2094 get_time(Now), 2095 format_time(string(S), Format, Now), 2096 atomics_to_string([Prefix0, S, ' '], Prefix). 2097add_message_context1(thread, Prefix0, Prefix) :- 2098 thread_self(Id0), 2099 Id0 \== main, 2100 !, 2101 ( atom(Id0) 2102 -> Id = Id0 2103 ; thread_property(Id0, id(Id)) 2104 ), 2105 format(string(Prefix), '~w[Thread ~w] ', [Prefix0, Id]).
2112print_message_lines(Stream, kind(Kind), Lines) :- 2113 !, 2114 msg_property(Kind, prefix(Prefix)), 2115 insert_prefix(Lines, Prefix, Ctx, PrefixLines), 2116 '$append'([ begin(Kind, Ctx) 2117 | PrefixLines 2118 ], 2119 [ end(Ctx) 2120 ], 2121 AllLines), 2122 print_message_lines(Stream, AllLines). 2123print_message_lines(Stream, Prefix, Lines) :- 2124 insert_prefix(Lines, Prefix, _, PrefixLines), 2125 print_message_lines(Stream, PrefixLines).
2129insert_prefix([at_same_line|Lines0], Prefix, Ctx, Lines) :- 2130 !, 2131 prefix_nl(Lines0, Prefix, Ctx, Lines). 2132insert_prefix(Lines0, Prefix, Ctx, [prefix(Prefix)|Lines]) :- 2133 prefix_nl(Lines0, Prefix, Ctx, Lines). 2134 2135prefix_nl([], _, _, [nl]). 2136prefix_nl([nl], _, _, [nl]) :- !. 2137prefix_nl([flush], _, _, [flush]) :- !. 2138prefix_nl([nl|T0], Prefix, Ctx, [nl, prefix(Prefix)|T]) :- 2139 !, 2140 prefix_nl(T0, Prefix, Ctx, T). 2141prefix_nl([ansi(Attrs,Fmt,Args)|T0], Prefix, Ctx, 2142 [ansi(Attrs,Fmt,Args,Ctx)|T]) :- 2143 !, 2144 prefix_nl(T0, Prefix, Ctx, T). 2145prefix_nl([H|T0], Prefix, Ctx, [H|T]) :- 2146 prefix_nl(T0, Prefix, Ctx, T).
2150print_message_lines(Stream, Lines) :- 2151 with_output_to( 2152 Stream, 2153 notrace(print_message_lines_guarded(current_output, Lines))). 2154 2155print_message_lines_guarded(_, []) :- !. 2156print_message_lines_guarded(S, [H|T]) :- 2157 line_element(S, H), 2158 print_message_lines_guarded(S, T). 2159 2160line_element(S, E) :- 2161 prolog:message_line_element(S, E), 2162 !. 2163line_element(S, full_stop) :- 2164 !, 2165 '$put_token'(S, '.'). % insert space if needed. 2166line_element(S, nl) :- 2167 !, 2168 nl(S). 2169line_element(S, prefix(Fmt-Args)) :- 2170 !, 2171 safe_format(S, Fmt, Args). 2172line_element(S, prefix(Fmt)) :- 2173 !, 2174 safe_format(S, Fmt, []). 2175line_element(S, flush) :- 2176 !, 2177 flush_output(S). 2178line_element(S, Fmt-Args) :- 2179 !, 2180 safe_format(S, Fmt, Args). 2181line_element(S, ansi(_, Fmt, Args)) :- 2182 !, 2183 safe_format(S, Fmt, Args). 2184line_element(S, ansi(_, Fmt, Args, _Ctx)) :- 2185 !, 2186 safe_format(S, Fmt, Args). 2187line_element(S, url(URL)) :- 2188 !, 2189 print_link(S, URL). 2190line_element(S, url(_URL, Fmt-Args)) :- 2191 !, 2192 safe_format(S, Fmt, Args). 2193line_element(S, url(_URL, Fmt)) :- 2194 !, 2195 safe_format(S, Fmt, []). 2196line_element(_, begin(_Level, _Ctx)) :- !. 2197line_element(_, end(_Ctx)) :- !. 2198line_element(S, Fmt) :- 2199 safe_format(S, Fmt, []). 2200 2201print_link(S, File:Line:Column) :- 2202 !, 2203 safe_format(S, '~w:~d:~d', [File, Line, Column]). 2204print_link(S, File:Line) :- 2205 !, 2206 safe_format(S, '~w:~d', [File, Line]). 2207print_link(S, File) :- 2208 safe_format(S, '~w', [File]).
2212safe_format(S, Fmt, Args) :- 2213 E = error(_,_), 2214 catch(format(S,Fmt,Args), E, 2215 format_failed(S,Fmt,Args,E)). 2216 2217format_failed(S, _Fmt, _Args, E) :- 2218 stream_property(S, error(true)), 2219 !, 2220 throw(E). 2221format_failed(S, Fmt, Args, error(E,_)) :- 2222 format(S, '~N [[ EXCEPTION while printing message ~q~n\c 2223 ~7|with arguments ~W:~n\c 2224 ~7|raised: ~W~n~4|]]~n', 2225 [ Fmt, 2226 Args, [quoted(true), max_depth(10)], 2227 E, [quoted(true), max_depth(10)] 2228 ]).
2234message_to_string(Term, Str) :- 2235 translate_message(Term, Actions, []), 2236 !, 2237 actions_to_format(Actions, Fmt, Args), 2238 format(string(Str), Fmt, Args). 2239 2240actions_to_format([], '', []) :- !. 2241actions_to_format([nl], '', []) :- !. 2242actions_to_format([Term, nl], Fmt, Args) :- 2243 !, 2244 actions_to_format([Term], Fmt, Args). 2245actions_to_format([nl|T], Fmt, Args) :- 2246 !, 2247 actions_to_format(T, Fmt0, Args), 2248 atom_concat('~n', Fmt0, Fmt). 2249actions_to_format([ansi(_Attrs, Fmt0, Args0)|Tail], Fmt, Args) :- 2250 !, 2251 actions_to_format(Tail, Fmt1, Args1), 2252 atom_concat(Fmt0, Fmt1, Fmt), 2253 append_args(Args0, Args1, Args). 2254actions_to_format([url(Pos)|Tail], Fmt, Args) :- 2255 !, 2256 actions_to_format(Tail, Fmt1, Args1), 2257 url_actions_to_format(url(Pos), Fmt1, Args1, Fmt, Args). 2258actions_to_format([url(URL, Label)|Tail], Fmt, Args) :- 2259 !, 2260 actions_to_format(Tail, Fmt1, Args1), 2261 url_actions_to_format(url(URL, Label), Fmt1, Args1, Fmt, Args). 2262actions_to_format([Fmt0-Args0|Tail], Fmt, Args) :- 2263 !, 2264 actions_to_format(Tail, Fmt1, Args1), 2265 atom_concat(Fmt0, Fmt1, Fmt), 2266 append_args(Args0, Args1, Args). 2267actions_to_format([Skip|T], Fmt, Args) :- 2268 action_skip(Skip), 2269 !, 2270 actions_to_format(T, Fmt, Args). 2271actions_to_format([Term|Tail], Fmt, Args) :- 2272 atomic(Term), 2273 !, 2274 actions_to_format(Tail, Fmt1, Args), 2275 atom_concat(Term, Fmt1, Fmt). 2276actions_to_format([Term|Tail], Fmt, Args) :- 2277 actions_to_format(Tail, Fmt1, Args1), 2278 atom_concat('~w', Fmt1, Fmt), 2279 append_args([Term], Args1, Args). 2280 2281action_skip(at_same_line). 2282action_skip(flush). 2283action_skip(begin(_Level, _Ctx)). 2284action_skip(end(_Ctx)). 2285 2286url_actions_to_format(url(File:Line:Column), Fmt1, Args1, Fmt, Args) :- 2287 !, 2288 atom_concat('~w:~d:~d', Fmt1, Fmt), 2289 append_args([File,Line,Column], Args1, Args). 2290url_actions_to_format(url(File:Line), Fmt1, Args1, Fmt, Args) :- 2291 !, 2292 atom_concat('~w:~d', Fmt1, Fmt), 2293 append_args([File,Line], Args1, Args). 2294url_actions_to_format(url(File), Fmt1, Args1, Fmt, Args) :- 2295 !, 2296 atom_concat('~w', Fmt1, Fmt), 2297 append_args([File], Args1, Args). 2298url_actions_to_format(url(_URL, Label), Fmt1, Args1, Fmt, Args) :- 2299 !, 2300 atom_concat('~w', Fmt1, Fmt), 2301 append_args([Label], Args1, Args). 2302 2303 2304append_args(M:Args0, Args1, M:Args) :- 2305 !, 2306 strip_module(Args1, _, A1), 2307 to_list(Args0, Args01), 2308 '$append'(Args01, A1, Args). 2309append_args(Args0, Args1, Args) :- 2310 strip_module(Args1, _, A1), 2311 to_list(Args0, Args01), 2312 '$append'(Args01, A1, Args). 2313 2314 /******************************* 2315 * MESSAGES TO PRINT ONCE * 2316 *******************************/ 2317 2318:- dynamic 2319 printed/2.
2325print_once(compatibility(_), _). 2326print_once(null_byte_in_path(_), _). 2327print_once(deprecated(_), _).
2333must_print(Level, Message) :- 2334 nonvar(Message), 2335 print_once(Message, Level), 2336 !, 2337 \+ printed(Message, Level), 2338 assert(printed(Message, Level)). 2339must_print(_, _)