36
37:- module(backward_compatibility,
38 [ '$arch'/2,
39 '$version'/1,
40 '$home'/1,
41 '$argv'/1,
42 '$set_prompt'/1,
43 '$strip_module'/3,
44 '$declare_module'/3,
45 '$module'/2,
46 at_initialization/1, 47 displayq/1,
48 displayq/2,
49 sformat/2, 50 sformat/3, 51 concat/3,
52 concat_atom/2, 53 concat_atom/3, 54 '$apropos_match'/2, 55 read_clause/1, 56 read_clause/2, 57 read_variables/2, 58 read_variables/3, 59 read_pending_input/3, 60 feature/2,
61 set_feature/2,
62 substring/4,
63 string_to_list/2, 64 string_to_atom/2, 65 flush/0,
66 write_ln/1, 67 proper_list/1, 68 free_variables/2, 69 hash_term/2, 70 checklist/2, 71 sublist/3, 72 sumlist/2, 73 convert_time/2, 74 convert_time/8, 75 'C'/3, 76 current_thread/2, 77 current_mutex/3, 78 message_queue_size/2, 79 lock_predicate/2, 80 unlock_predicate/2, 81 current_module/2, 82 export_list/2, 83 setup_and_call_cleanup/3, 84 setup_and_call_cleanup/4, 85 merge/3, 86 merge_set/3, 87 (index)/1, 88 hash/1, 89 set_base_module/1, 90 eval_license/0,
91 trie_insert_new/3, 92 thread_at_exit/1, 93 read_history/6, 94 95 '$sig_atomic'/1 96 ]). 97:- autoload(library(apply),[maplist/3,maplist/2]). 98:- autoload(library(lists),[sum_list/2]). 99:- autoload(library(system),[lock_predicate/1,unlock_predicate/1]). 100
101
102:- meta_predicate
103 at_initialization(0),
104 setup_and_call_cleanup(0,0,0),
105 setup_and_call_cleanup(0,0,?,0),
106 checklist(1, +),
107 sublist(1, +, ?),
108 index(:),
109 hash(:),
110 set_base_module(:),
111 thread_at_exit(0),
112 '$sig_atomic'(0).
132'$arch'(Arch, unknown) :-
133 current_prolog_flag(arch, Arch).
139'$version'(Version) :-
140 current_prolog_flag(version, Version).
148'$home'(Home) :-
149 current_prolog_flag(home, Home).
156'$argv'(Argv) :-
157 current_prolog_flag(os_argv, Argv).
165'$set_prompt'(Prompt) :-
166 ( is_list(Prompt)
167 -> Prompt0 = Prompt
168 ; atom_codes(Prompt, Prompt0)
169 ),
170 maplist(percent_to_tilde, Prompt0, Prompt1),
171 atom_codes(Atom, Prompt1),
172 set_prolog_flag(toplevel_prompt, Atom).
173
174percent_to_tilde(0'%, 0'~) :- !.
175percent_to_tilde(X, X).
185displayq(Term) :-
186 write_term(Term, [ignore_ops(true),quoted(true)]).
187displayq(Stream, Term) :-
188 write_term(Stream, Term, [ignore_ops(true),quoted(true)]).
196:- module_transparent sformat/2, sformat/3. 197
198sformat(String, Format) :-
199 format(string(String), Format, []).
200sformat(String, Format, Arguments) :-
201 format(string(String), Format, Arguments).
207concat(A, B, C) :-
208 atom_concat(A, B, C).
217concat_atom([A, B], C) :-
218 !,
219 atom_concat(A, B, C).
220concat_atom(L, Atom) :-
221 atomic_list_concat(L, Atom).
232concat_atom(L, Sep, Atom) :-
233 atomic_list_concat(L, Sep, Atom).
240'$apropos_match'(Needle, Haystack) :-
241 sub_atom_icasechk(Haystack, _, Needle).
247read_clause(Term) :-
248 read_clause(current_input, Term).
254read_clause(Stream, Term) :-
255 read_clause(Stream, Term, [process_comment(false)]).
262read_variables(Term, Vars) :-
263 read_term(Term, [variable_names(Vars)]).
264
265read_variables(Stream, Term, Vars) :-
266 read_term(Stream, Term, [variable_names(Vars)]).
272read_pending_input(Stream, Codes, Tail) :-
273 read_pending_codes(Stream, Codes, Tail).
282feature(Key, Value) :-
283 current_prolog_flag(Key, Value).
284
285set_feature(Key, Value) :-
286 set_prolog_flag(Key, Value).
294substring(String, Offset, Length, Sub) :-
295 Offset0 is Offset - 1,
296 sub_string(String, Offset0, Length, _After, Sub).
305string_to_list(String, Codes) :-
306 string_codes(String, Codes).
315string_to_atom(Atom, String) :-
316 atom_string(String, Atom).
322flush :-
323 flush_output.
329write_ln(X) :-
330 writeln(X).
340proper_list(List) :-
341 is_list(List).
350free_variables(Term, Variables) :-
351 term_variables(Term, Variables).
360hash_term(Term, Hash) :-
361 term_hash(Term, Hash).
368checklist(Goal, List) :-
369 maplist(Goal, List).
379sublist(_, [], []) :- !.
380sublist(Goal, [H|T], Sub) :-
381 call(Goal, H),
382 !,
383 Sub = [H|R],
384 sublist(Goal, T, R).
385sublist(Goal, [_|T], R) :-
386 sublist(Goal, T, R).
394sumlist(List, Sum) :-
395 sum_list(List, Sum).
406:- module_transparent
407 '$strip_module'/3. 408
409'$strip_module'(Term, Module, Plain) :-
410 strip_module(Term, Module, Plain).
414'$module'(OldTypeIn, NewTypeIn) :-
415 '$current_typein_module'(OldTypeIn),
416 '$set_typein_module'(NewTypeIn).
422'$declare_module'(Module, File, Line) :-
423 '$declare_module'(Module, user, user, File, Line, false).
432at_initialization(Goal) :-
433 initialization(Goal, restore).
445convert_time(Stamp, String) :-
446 format_time(string(String), '%+', Stamp).
461convert_time(Stamp, Y, Mon, Day, Hour, Min, Sec, MilliSec) :-
462 stamp_date_time(Stamp,
463 date(Y, Mon, Day,
464 Hour, Min, FSec,
465 _, _, _),
466 local),
467 Sec is integer(float_integer_part(FSec)),
468 MilliSec is integer(float_fractional_part(FSec)*1000).
477'C'([H|T], H, T).
484current_thread(Thread, Status) :-
485 nonvar(Thread),
486 !,
487 catch(thread_property(Thread, status(Status)),
488 error(existence_error(thread, _), _),
489 fail).
490current_thread(Thread, Status) :-
491 thread_property(Thread, status(Status)).
497current_mutex(Mutex, Owner, Count) :-
498 nonvar(Mutex),
499 !,
500 catch(mutex_property(Mutex, status(Status)),
501 error(existence_error(mutex, _), _),
502 fail),
503 map_mutex_status(Status, Owner, Count).
504current_mutex(Mutex, Owner, Count) :-
505 mutex_property(Mutex, status(Status)),
506 map_mutex_status(Status, Owner, Count).
507
508map_mutex_status(unlocked, [], 0).
509map_mutex_status(locked(Owner, Count), Owner, Count).
518message_queue_size(Queue, Size) :-
519 message_queue_property(Queue, size(Size)).
526:- module_transparent
527 lock_predicate/2,
528 unlock_predicate/2. 529
530lock_predicate(Name, Arity) :-
531 lock_predicate(Name/Arity).
532
533unlock_predicate(Name, Arity) :-
534 unlock_predicate(Name/Arity).
542current_module(Module, File) :-
543 module_property(Module, file(File)).
551export_list(Module, List) :-
552 module_property(Module, exports(List)).
560setup_and_call_cleanup(Setup, Goal, Cleanup) :-
561 setup_call_cleanup(Setup, Goal, Cleanup).
570setup_and_call_cleanup(Setup, Goal, Catcher, Cleanup) :-
571 setup_call_catcher_cleanup(Setup, Goal, Catcher,Cleanup).
581merge_set([], L, L) :- !.
582merge_set(L, [], L) :- !.
583merge_set([H1|T1], [H2|T2], [H1|R]) :- H1 @< H2, !, merge_set(T1, [H2|T2], R).
584merge_set([H1|T1], [H2|T2], [H2|R]) :- H1 @> H2, !, merge_set([H1|T1], T2, R).
585merge_set([H1|T1], [H2|T2], [H1|R]) :- H1 == H2, merge_set(T1, T2, R).
596merge([], L, L) :- !.
597merge(L, [], L) :- !.
598merge([H1|T1], [H2|T2], [H|R]) :-
599 ( H1 @=< H2
600 -> H = H1,
601 merge(T1, [H2|T2], R)
602 ; H = H2,
603 merge([H1|T1], T2, R)
604 ).
614index(Head) :-
615 print_message(warning, decl_no_effect(index(Head))).
622hash(PI) :-
623 print_message(warning, decl_no_effect(hash(PI))).
631set_base_module(M:Base) :-
632 set_module(M:base(Base)).
638eval_license :-
639 license.
645trie_insert_new(Trie, Term, Handle) :-
646 trie_insert(Trie, Term, [], Handle).
653thread_at_exit(Goal) :-
654 prolog_listen(this_thread_exit, Goal).
660read_history(Show, Help, Special, Prompt, Term, Bindings) :-
661 read_term_with_history(
662 Term,
663 [ show(Show),
664 help(Help),
665 no_save(Special),
666 prompt(Prompt),
667 variable_names(Bindings)
668 ]).
676'$sig_atomic'(Goal) :-
677 sig_atomic(Goal)
Backward compatibility
This library defines predicates that used to exist in older version of SWI-Prolog, but are considered obsolete as there functionality is neatly covered by new features. Most often, these constructs are superseded by ISO-standard compliant predicates.
Please also note the existence of
quintus.pl
andedinburgh.pl
for more compatibility predicates.