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) 1985-2017, University of Amsterdam 7 VU University Amsterdam 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions 12 are met: 13 14 1. Redistributions of source code must retain the above copyright 15 notice, this list of conditions and the following disclaimer. 16 17 2. Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in 19 the documentation and/or other materials provided with the 20 distribution. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 POSSIBILITY OF SUCH DAMAGE. 34*/ 35 36:- module(backward_compatibility, 37 [ '$arch'/2, 38 '$version'/1, 39 '$home'/1, 40 '$argv'/1, 41 '$set_prompt'/1, 42 '$strip_module'/3, 43 '$declare_module'/3, 44 '$module'/2, 45 at_initialization/1, % :Goal 46 displayq/1, 47 displayq/2, 48 sformat/2, % -String, +Fmt 49 sformat/3, % -String, +Fmt, +Args 50 concat/3, 51 concat_atom/2, % +List, -Atom 52 concat_atom/3, % +List, +Sep, -Atom 53 '$apropos_match'/2, % +Needle, +Hashstack 54 read_clause/1, % -Term 55 read_clause/2, % +Stream, -Term 56 read_variables/2, % -Term, -VariableNames 57 read_variables/3, % +Stream, -Term, -VariableNames 58 read_pending_input/3, % +Stream, -List, ?Tail 59 feature/2, 60 set_feature/2, 61 substring/4, 62 string_to_list/2, % ?String, ?Codes 63 string_to_atom/2, % ?String, ?Atom 64 flush/0, 65 write_ln/1, % +Term 66 proper_list/1, % @Term 67 free_variables/2, % +Term, -Variables 68 subsumes_chk/2, % @Generic, @Specific 69 subsumes/2, % @Generic, @Specific 70 hash_term/2, % +Term, -Hash 71 checklist/2, % :Goal, +List 72 sublist/3, % :Goal, +List, -Sublist 73 sumlist/2, % +List, -Sum 74 convert_time/2, % +Stamp, -String 75 convert_time/8, % +String, -YMDmhs.ms 76 'C'/3, % +List, -Head, -Tail 77 current_thread/2, % ?Thread, ?Status 78 current_mutex/3, % ?Mutex, ?Owner, ?Count 79 message_queue_size/2, % +Queue, -TermsWaiting 80 lock_predicate/2, % +Name, +Arity 81 unlock_predicate/2, % +Name, +Arity 82 current_module/2, % ?Module, ?File 83 export_list/2, % +Module, -Exports 84 setup_and_call_cleanup/3, % :Setup, :Goal, :Cleanup 85 setup_and_call_cleanup/4, % :Setup, :Goal, ?Catcher, :Cleanup 86 merge/3, % +List1, +List2, -Union 87 merge_set/3, % +Set1, +Set2, -Union 88 index/1, % :Head 89 hash/1, % :PI 90 set_base_module/1, % :Base 91 eval_license/0, 92 trie_insert_new/3 % +Trie, +Term, -Node 93 ]). 94:- use_module(apply, [maplist/2]). 95:- use_module(system, [lock_predicate/1, unlock_predicate/1]). 96:- use_module(lists, [sum_list/2]). 97 98:- meta_predicate 99 at_initialization( ), 100 setup_and_call_cleanup( , , ), 101 setup_and_call_cleanup( , , , ), 102 checklist( , ), 103 sublist( , , ), 104 index( ), 105 hash( ), 106 set_base_module( ). 107 108/** <module> Backward compatibility 109 110This library defines predicates that used to exist in older version of 111SWI-Prolog, but are considered obsolete as there functionality is neatly 112covered by new features. Most often, these constructs are superceeded by 113ISO-standard compliant predicates. 114 115Please also note the existence of quintus.pl and edinburgh.pl for more 116compatibility predicates. 117 118@see gxref/0 can be used to find files that import from 119 library(backcomp) and thus reply on deprecated features. 120*/ 121 122%! '$arch'(-Architecture, -Version) is det. 123% 124% @deprecated use current_prolog_flag(arch, Architecture) 125 126'$arch'(Arch, unknown) :- 127 current_prolog_flag(arch, Arch). 128 129%! '$version'(Version:integer) is det. 130% 131% @deprecated use current_prolog_flag(version, Version) 132 133'$version'(Version) :- 134 current_prolog_flag(version, Version). 135 136%! '$home'(-SWIPrologDir) is det. 137% 138% @deprecated use current_prolog_flag(home, SWIPrologDir) 139% @see file_search_path/2, absolute_file_name/3, The Prolog home 140% directory is available through the alias =swi=. 141 142'$home'(Home) :- 143 current_prolog_flag(home, Home). 144 145%! '$argv'(-Argv:list) is det. 146% 147% @deprecated use current_prolog_flag(os_argv, Argv) or 148% current_prolog_flag(argv, Argv) 149 150'$argv'(Argv) :- 151 current_prolog_flag(os_argv, Argv). 152 153%! '$set_prompt'(+Prompt) is det. 154% 155% Set the prompt for the toplevel 156% 157% @deprecated use set_prolog_flag(toplevel_prompt, Prompt). 158 159'$set_prompt'(Prompt) :- 160 ( is_list(Prompt) 161 -> Prompt0 = Prompt 162 ; atom_codes(Prompt, Prompt0) 163 ), 164 maplist(percent_to_tilde, Prompt0, Prompt1), 165 atom_codes(Atom, Prompt1), 166 set_prolog_flag(toplevel_prompt, Atom). 167 168percent_to_tilde(0'%, 0'~) :- !. 169percent_to_tilde(X, X). 170 171 172%! displayq(@Term) is det. 173%! displayq(+Stream, @Term) is det. 174% 175% Write term ignoring operators and quote atoms. 176% 177% @deprecated Use write_term/3 or write_canonical/2. 178 179displayq(Term) :- 180 write_term(Term, [ignore_ops(true),quoted(true)]). 181displayq(Stream, Term) :- 182 write_term(Stream, Term, [ignore_ops(true),quoted(true)]). 183 184 185%! sformat(-String, +Format, +Args) is det. 186%! sformat(-String, +Format) is det. 187% 188% @deprecated Use format/3 as =|format(string(String), ...)|= 189 190:- module_transparent sformat/2, sformat/3. 191 192sformat(String, Format) :- 193 format(string(String), Format, []). 194sformat(String, Format, Arguments) :- 195 format(string(String), Format, Arguments). 196 197%! concat(+Atom1, +Atom2, -Atom) is det. 198% 199% @deprecated Use ISO atom_concat/3 200 201concat(A, B, C) :- 202 atom_concat(A, B, C). 203 204%! concat_atom(+List, -Atom) is det. 205% 206% Concatenate a list of atomic values to an atom. 207% 208% @deprecated Use atomic_list_concat/2 as proposed by the prolog 209% commons initiative. 210 211concat_atom([A, B], C) :- 212 !, 213 atom_concat(A, B, C). 214concat_atom(L, Atom) :- 215 atomic_list_concat(L, Atom). 216 217 218%! concat_atom(+List, +Seperator, -Atom) is det. 219% 220% Concatenate a list of atomic values to an atom, inserting Seperator 221% between each consecutive elements. 222% 223% @deprecated Use atomic_list_concat/3 as proposed by the prolog 224% commons initiative. 225 226concat_atom(L, Sep, Atom) :- 227 atomic_list_concat(L, Sep, Atom). 228 229%! '$apropos_match'(+Needle, +Haystack) is semidet. 230% 231% True if Needle is a sub atom of Haystack. Ignores the case 232% of Haystack. 233 234'$apropos_match'(Needle, Haystack) :- 235 sub_atom_icasechk(Haystack, _, Needle). 236 237%! read_clause(-Term) is det. 238% 239% @deprecated Use read_clause/3 or read_term/3. 240 241read_clause(Term) :- 242 read_clause(current_input, Term). 243 244%! read_clause(+Stream, -Term) is det. 245% 246% @deprecated Use read_clause/3 or read_term/3. 247 248read_clause(Stream, Term) :- 249 read_clause(Stream, Term, [process_comment(false)]). 250 251%! read_variables(-Term, -Bindings) is det. 252%! read_variables(+In:stream, -Term, -Bindings) is det. 253% 254% @deprecated Use ISO read_term/2 or read_term/3. 255 256read_variables(Term, Vars) :- 257 read_term(Term, [variable_names(Vars)]). 258 259read_variables(Stream, Term, Vars) :- 260 read_term(Stream, Term, [variable_names(Vars)]). 261 262%! read_pending_input(+Stream, -Codes, ?Tail) is det. 263% 264% @deprecated Use read_pending_codes/3. 265 266read_pending_input(Stream, Codes, Tail) :- 267 read_pending_codes(Stream, Codes, Tail). 268 269%! feature(?Key, ?Value) is nondet. 270%! set_feature(+Key, @Term) is det. 271% 272% Control Prolog flags. 273% 274% @deprecated Use ISO current_prolog_flag/2 and set_prolog_flag/2. 275 276feature(Key, Value) :- 277 current_prolog_flag(Key, Value). 278 279set_feature(Key, Value) :- 280 set_prolog_flag(Key, Value). 281 282%! substring(+String, +Offset, +Length, -Sub) 283% 284% Predecessor of sub_string using 1-based Offset. 285% 286% @deprecated Use sub_string/5. 287 288substring(String, Offset, Length, Sub) :- 289 Offset0 is Offset - 1, 290 sub_string(String, Offset0, Length, _After, Sub). 291 292%! string_to_list(?String, ?Codes) is det. 293% 294% Bi-directional conversion between a string and a list of 295% character codes. 296% 297% @deprecated Use string_codes/2. 298 299string_to_list(String, Codes) :- 300 string_codes(String, Codes). 301 302%! string_to_atom(?String, ?Atom) is det. 303% 304% Bi-directional conversion between string and atom. 305% 306% @deprecated Use atom_string/2. Note that the order of the 307% arguments is reversed. 308 309string_to_atom(Atom, String) :- 310 atom_string(String, Atom). 311 312%! flush is det. 313% 314% @deprecated use ISO flush_output/0. 315 316flush :- 317 flush_output. 318 319%! write_ln(X) is det 320% 321% @deprecated Use writeln(X). 322 323write_ln(X) :- 324 writeln(X). 325 326%! proper_list(+List) 327% 328% Old SWI-Prolog predicate to check for a list that really ends 329% in a []. There is not much use for the quick is_list, as in 330% most cases you want to process the list element-by-element anyway. 331% 332% @deprecated Use ISO is_list/1. 333 334proper_list(List) :- 335 is_list(List). 336 337%! free_variables(+Term, -Variables) 338% 339% Return a list of unbound variables in Term. The name 340% term_variables/2 is more widely used. 341% 342% @deprecated Use term_variables/2. 343 344free_variables(Term, Variables) :- 345 term_variables(Term, Variables). 346 347%! subsumes_chk(@Generic, @Specific) 348% 349% True if Generic can be made equivalent to Specific without 350% changing Specific. 351% 352% @deprecated Replace by subsumes_term/2. 353 354subsumes_chk(Generic, Specific) :- 355 subsumes_term(Generic, Specific). 356 357%! subsumes(+Generic, @Specific) 358% 359% True if Generic is unified to Specific without changing 360% Specific. 361% 362% @deprecated It turns out that calls to this predicate almost 363% always should have used subsumes_term/2. Also the name is 364% misleading. In case this is really needed, one is adviced to 365% follow subsumes_term/2 with an explicit unification. 366 367subsumes(Generic, Specific) :- 368 subsumes_term(Generic, Specific), 369 Generic = Specific. 370 371%! hash_term(+Term, -Hash) is det. 372% 373% If Term is ground, Hash is unified to an integer representing 374% a hash for Term. Otherwise Hash is left unbound. 375% 376% @deprecated Use term_hash/2. 377 378hash_term(Term, Hash) :- 379 term_hash(Term, Hash). 380 381%! checklist(:Goal, +List) 382% 383% @deprecated Use maplist/2 384 385 386checklist(Goal, List) :- 387 maplist(Goal, List). 388 389%! sublist(:Goal, +List1, ?List2) 390% 391% Succeeds if List2 unifies with a list holding those terms for wich 392% call(Goal, Elem) succeeds. 393% 394% @deprecated Use include/3 from library(apply) 395% @compat DEC10 library 396 397sublist(_, [], []) :- !. 398sublist(Goal, [H|T], Sub) :- 399 call(Goal, H), 400 !, 401 Sub = [H|R], 402 sublist(Goal, T, R). 403sublist(Goal, [_|T], R) :- 404 sublist(Goal, T, R). 405 406%! sumlist(+List, -Sum) is det. 407% 408% True when Sum is the list of all numbers in List. 409% 410% @deprecated Use sum_list/2 411 412sumlist(List, Sum) :- 413 sum_list(List, Sum). 414 415%! '$strip_module'(+Term, -Module, -Plain) 416% 417% This used to be an internal predicate. It was added to the XPCE 418% compatibility library without $ and since then used at many 419% places. From 5.4.1 onwards strip_module/3 is built-in and the $ 420% variation is added here for compatibility. 421% 422% @deprecated Use strip_module/3. 423 424:- module_transparent 425 '$strip_module'/3. 426 427'$strip_module'(Term, Module, Plain) :- 428 strip_module(Term, Module, Plain). 429 430%! '$module'(-OldTypeIn, +NewTypeIn) 431 432'$module'(OldTypeIn, NewTypeIn) :- 433 '$current_typein_module'(OldTypeIn), 434 '$set_typein_module'(NewTypeIn). 435 436%! '$declare_module'(Module, File, Line) 437% 438% Used in triple20 particle library. Should use a public interface 439 440'$declare_module'(Module, File, Line) :- 441 '$declare_module'(Module, user, user, File, Line, false). 442 443 444%! at_initialization(:Goal) is det. 445% 446% Register goal only to be run if a saved state is restored. 447% 448% @deprecated Use initialization(Goal, restore) 449 450at_initialization(Goal) :- 451 initialization(, restore). 452 453%! convert_time(+Stamp, -String) 454% 455% Convert a time-stamp as obtained though get_time/1 into a textual 456% representation using the C-library function ctime(). The value is 457% returned as a SWI-Prolog string object (see section 4.23). See 458% also convert_time/8. 459% 460% @deprecated Use format_time/3. 461 462 463convert_time(Stamp, String) :- 464 format_time(string(String), '%+', Stamp). 465 466%! convert_time(+Stamp, -Y, -Mon, -Day, -Hour, -Min, -Sec, -MilliSec) 467% 468% Convert a time stamp, provided by get_time/1, time_file/2, 469% etc. Year is unified with the year, Month with the month number 470% (January is 1), Day with the day of the month (starting with 1), 471% Hour with the hour of the day (0--23), Minute with the minute 472% (0--59). Second with the second (0--59) and MilliSecond with the 473% milliseconds (0--999). Note that the latter might not be accurate 474% or might always be 0, depending on the timing capabilities of the 475% system. See also convert_time/2. 476% 477% @deprecated Use stamp_date_time/3. 478 479convert_time(Stamp, Y, Mon, Day, Hour, Min, Sec, MilliSec) :- 480 stamp_date_time(Stamp, 481 date(Y, Mon, Day, 482 Hour, Min, FSec, 483 _, _, _), 484 local), 485 Sec is integer(float_integer_part(FSec)), 486 MilliSec is integer(float_fractional_part(FSec)*1000). 487 488%! 'C'(?List, ?Head, ?Tail) is det. 489% 490% Used to be generated by DCG. Some people appear to be using in 491% in normal code too. 492% 493% @deprecated Do not use in normal code; DCG no longer generates it. 494 495'C'([H|T], H, T). 496 497 498%! current_thread(?Thread, ?Status) is nondet. 499% 500% @deprecated Replaced by thread_property/2 501 502current_thread(Thread, Status) :- 503 nonvar(Thread), 504 !, 505 catch(thread_property(Thread, status(Status)), 506 error(existence_error(thread, _), _), 507 fail). 508current_thread(Thread, Status) :- 509 thread_property(Thread, status(Status)). 510 511%! current_mutex(?Mutex, ?Owner, ?Count) is nondet. 512% 513% @deprecated Replaced by mutex_property/2 514 515current_mutex(Mutex, Owner, Count) :- 516 nonvar(Mutex), 517 !, 518 catch(mutex_property(Mutex, status(Status)), 519 error(existence_error(mutex, _), _), 520 fail), 521 map_mutex_status(Status, Owner, Count). 522current_mutex(Mutex, Owner, Count) :- 523 mutex_property(Mutex, status(Status)), 524 map_mutex_status(Status, Owner, Count). 525 526map_mutex_status(unlocked, [], 0). 527map_mutex_status(locked(Owner, Count), Owner, Count). 528 529 530%! message_queue_size(+Queue, -Size) is det. 531% 532% True if Queue holds Size terms. 533% 534% @deprecated Please use message_queue_property(Queue, Size) 535 536message_queue_size(Queue, Size) :- 537 message_queue_property(Queue, size(Size)). 538 539%! lock_predicate(+Name, +Arity) is det. 540%! unlock_predicate(+Name, +Arity) is det. 541% 542% @deprecated see lock_predicate/1 and unlock_predicate/1. 543 544:- module_transparent 545 lock_predicate/2, 546 unlock_predicate/2. 547 548lock_predicate(Name, Arity) :- 549 lock_predicate(Name/Arity). 550 551unlock_predicate(Name, Arity) :- 552 unlock_predicate(Name/Arity). 553 554%! current_module(?Module, ?File) is nondet. 555% 556% True if Module is a module loaded from File. 557% 558% @deprecated Use module_property(Module, file(File)) 559 560current_module(Module, File) :- 561 module_property(Module, file(File)). 562 563%! export_list(+Module, -List) is det. 564% 565% Module exports the predicates of List. 566% 567% @deprecated Use module_property(Module, exports(List)) 568 569export_list(Module, List) :- 570 module_property(Module, exports(List)). 571 572%! setup_and_call_cleanup(:Setup, :Goal, :Cleanup). 573% 574% Call Cleanup once after Goal is finished. 575% 576% @deprecated Use setup_call_cleanup/3. 577 578setup_and_call_cleanup(Setup, Goal, Cleanup) :- 579 setup_call_cleanup(, , ). 580 581%! setup_and_call_cleanup(:Setup, :Goal, Catcher, :Cleanup). 582% 583% Call Cleanup once after Goal is finished, with Catcher 584% unified to the reason 585% 586% @deprecated Use setup_call_cleanup/3. 587 588setup_and_call_cleanup(Setup, Goal, Catcher, Cleanup) :- 589 setup_call_catcher_cleanup(, , Catcher,). 590 591%! merge_set(+Set1, +Set2, -Set3) 592% 593% Merge the ordered sets Set1 and Set2 into a new ordered set 594% without duplicates. 595% 596% @deprecated New code should use ord_union/3 from 597% library(ordsets) 598 599merge_set([], L, L) :- !. 600merge_set(L, [], L) :- !. 601merge_set([H1|T1], [H2|T2], [H1|R]) :- H1 @< H2, !, merge_set(T1, [H2|T2], R). 602merge_set([H1|T1], [H2|T2], [H2|R]) :- H1 @> H2, !, merge_set([H1|T1], T2, R). 603merge_set([H1|T1], [H2|T2], [H1|R]) :- H1 == H2, merge_set(T1, T2, R). 604 605 606%! merge(+List1, +List2, -List3) 607% 608% Merge the ordered sets List1 and List2 into a new ordered list. 609% Duplicates are not removed and their order is maintained. 610% 611% @deprecated The name of this predicate is far too general for 612% a rather specific function. 613 614merge([], L, L) :- !. 615merge(L, [], L) :- !. 616merge([H1|T1], [H2|T2], [H|R]) :- 617 ( H1 @=< H2 618 -> H = H1, 619 merge(T1, [H2|T2], R) 620 ; H = H2, 621 merge([H1|T1], T2, R) 622 ). 623 624%! index(:Head) is det. 625% 626% Prepare the predicate indicated by Head for multi-argument 627% indexing. 628% 629% @deprecated As of version 5.11.29, SWI-Prolog performs 630% just-in-time indexing on all arguments. 631 632index(Head) :- 633 print_message(warning, decl_no_effect(index(Head))). 634 635%! hash(:PredInd) is det. 636% 637% Demands PredInd to be indexed using a hash-table. This is 638% handled dynamically. 639 640hash(PI) :- 641 print_message(warning, decl_no_effect(hash(PI))). 642 643%! set_base_module(:Base) is det. 644% 645% Set the default module from whic we inherit. 646% 647% @deprecated Equivalent to set_module(base(Base)). 648 649set_base_module(M:Base) :- 650 set_module(M:base(Base)). 651 652%! eval_license is det. 653% 654% @deprecated Equivalent to license/0 655 656eval_license :- 657 license. 658 659%! trie_insert_new(+Trie, +Term, -Handle) is semidet. 660% 661% @deprecated use trie_insert/4. 662 663trie_insert_new(Trie, Term, Handle) :- 664 trie_insert(Trie, Term, [], Handle)