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