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 write_length/3, 68 proper_list/1, 69 free_variables/2, 70 hash_term/2, 71 checklist/2, 72 sublist/3, 73 sumlist/2, 74 convert_time/2, 75 convert_time/8, 76 'C'/3, 77 current_thread/2, 78 current_mutex/3, 79 message_queue_size/2, 80 lock_predicate/2, 81 unlock_predicate/2, 82 current_module/2, 83 export_list/2, 84 call_cleanup/3, 85 setup_and_call_cleanup/3, 86 setup_and_call_cleanup/4, 87 merge/3, 88 merge_set/3, 89 (index)/1, 90 hash/1, 91 set_base_module/1, 92 eval_license/0,
93 trie_insert_new/3, 94 thread_at_exit/1, 95 read_history/6, 96 97 '$sig_atomic'/1 98 ]). 99:- autoload(library(apply),[maplist/3,maplist/2]). 100:- autoload(library(lists),[sum_list/2]). 101:- autoload(library(system),[lock_predicate/1,unlock_predicate/1]). 102
103
104:- meta_predicate
105 at_initialization(0),
106 call_cleanup(0,?,0),
107 setup_and_call_cleanup(0,0,0),
108 setup_and_call_cleanup(0,0,?,0),
109 checklist(1, +),
110 sublist(1, +, ?),
111 index(:),
112 hash(:),
113 set_base_module(:),
114 thread_at_exit(0),
115 '$sig_atomic'(0).
135'$arch'(Arch, unknown) :-
136 current_prolog_flag(arch, Arch).
142'$version'(Version) :-
143 current_prolog_flag(version, Version).
151'$home'(Home) :-
152 current_prolog_flag(home, Home).
159'$argv'(Argv) :-
160 current_prolog_flag(os_argv, Argv).
168'$set_prompt'(Prompt) :-
169 ( is_list(Prompt)
170 -> Prompt0 = Prompt
171 ; atom_codes(Prompt, Prompt0)
172 ),
173 maplist(percent_to_tilde, Prompt0, Prompt1),
174 atom_codes(Atom, Prompt1),
175 set_prolog_flag(toplevel_prompt, Atom).
176
177percent_to_tilde(0'%, 0'~) :- !.
178percent_to_tilde(X, X).
188displayq(Term) :-
189 write_term(Term, [ignore_ops(true),quoted(true)]).
190displayq(Stream, Term) :-
191 write_term(Stream, Term, [ignore_ops(true),quoted(true)]).
199:- module_transparent sformat/2, sformat/3. 200
201sformat(String, Format) :-
202 format(string(String), Format, []).
203sformat(String, Format, Arguments) :-
204 format(string(String), Format, Arguments).
210concat(A, B, C) :-
211 atom_concat(A, B, C).
220concat_atom([A, B], C) :-
221 !,
222 atom_concat(A, B, C).
223concat_atom(L, Atom) :-
224 atomic_list_concat(L, Atom).
235concat_atom(L, Sep, Atom) :-
236 atomic_list_concat(L, Sep, Atom).
243'$apropos_match'(Needle, Haystack) :-
244 sub_atom_icasechk(Haystack, _, Needle).
250read_clause(Term) :-
251 read_clause(current_input, Term).
257read_clause(Stream, Term) :-
258 read_clause(Stream, Term, [process_comment(false)]).
265read_variables(Term, Vars) :-
266 read_term(Term, [variable_names(Vars)]).
267
268read_variables(Stream, Term, Vars) :-
269 read_term(Stream, Term, [variable_names(Vars)]).
275read_pending_input(Stream, Codes, Tail) :-
276 read_pending_codes(Stream, Codes, Tail).
285feature(Key, Value) :-
286 current_prolog_flag(Key, Value).
287
288set_feature(Key, Value) :-
289 set_prolog_flag(Key, Value).
297substring(String, Offset, Length, Sub) :-
298 Offset0 is Offset - 1,
299 sub_string(String, Offset0, Length, _After, Sub).
308string_to_list(String, Codes) :-
309 string_codes(String, Codes).
318string_to_atom(Atom, String) :-
319 atom_string(String, Atom).
325flush :-
326 flush_output.
332write_ln(X) :-
333 writeln(X).
339write_length(Term, Length, Options) :-
340 '$option'(max_length(ML), Options),
341 !,
342 write_size(Term, Length, _, [max_width(ML)]).
343write_length(Term, Length, _Options) :-
344 write_size(Term, Length, _, []).
354proper_list(List) :-
355 is_list(List).
364free_variables(Term, Variables) :-
365 term_variables(Term, Variables).
374hash_term(Term, Hash) :-
375 term_hash(Term, Hash).
382checklist(Goal, List) :-
383 maplist(Goal, List).
393sublist(_, [], []) :- !.
394sublist(Goal, [H|T], Sub) :-
395 call(Goal, H),
396 !,
397 Sub = [H|R],
398 sublist(Goal, T, R).
399sublist(Goal, [_|T], R) :-
400 sublist(Goal, T, R).
408sumlist(List, Sum) :-
409 sum_list(List, Sum).
420:- module_transparent
421 '$strip_module'/3. 422
423'$strip_module'(Term, Module, Plain) :-
424 strip_module(Term, Module, Plain).
428'$module'(OldTypeIn, NewTypeIn) :-
429 '$current_typein_module'(OldTypeIn),
430 '$set_typein_module'(NewTypeIn).
436'$declare_module'(Module, File, Line) :-
437 '$declare_module'(Module, user, user, File, Line, false).
446at_initialization(Goal) :-
447 initialization(Goal, restore).
459convert_time(Stamp, String) :-
460 format_time(string(String), '%+', Stamp).
475convert_time(Stamp, Y, Mon, Day, Hour, Min, Sec, MilliSec) :-
476 stamp_date_time(Stamp,
477 date(Y, Mon, Day,
478 Hour, Min, FSec,
479 _, _, _),
480 local),
481 Sec is integer(float_integer_part(FSec)),
482 MilliSec is integer(float_fractional_part(FSec)*1000).
491'C'([H|T], H, T).
498current_thread(Thread, Status) :-
499 nonvar(Thread),
500 !,
501 catch(thread_property(Thread, status(Status)),
502 error(existence_error(thread, _), _),
503 fail).
504current_thread(Thread, Status) :-
505 thread_property(Thread, status(Status)).
511current_mutex(Mutex, Owner, Count) :-
512 nonvar(Mutex),
513 !,
514 catch(mutex_property(Mutex, status(Status)),
515 error(existence_error(mutex, _), _),
516 fail),
517 map_mutex_status(Status, Owner, Count).
518current_mutex(Mutex, Owner, Count) :-
519 mutex_property(Mutex, status(Status)),
520 map_mutex_status(Status, Owner, Count).
521
522map_mutex_status(unlocked, [], 0).
523map_mutex_status(locked(Owner, Count), Owner, Count).
532message_queue_size(Queue, Size) :-
533 message_queue_property(Queue, size(Size)).
540:- module_transparent
541 lock_predicate/2,
542 unlock_predicate/2. 543
544lock_predicate(Name, Arity) :-
545 lock_predicate(Name/Arity).
546
547unlock_predicate(Name, Arity) :-
548 unlock_predicate(Name/Arity).
556current_module(Module, File) :-
557 module_property(Module, file(File)).
565export_list(Module, List) :-
566 module_property(Module, exports(List)).
574call_cleanup(Goal, Catcher, Cleanup) :-
575 setup_call_catcher_cleanup(true, Goal, Catcher, Cleanup).
583setup_and_call_cleanup(Setup, Goal, Cleanup) :-
584 setup_call_cleanup(Setup, Goal, Cleanup).
593setup_and_call_cleanup(Setup, Goal, Catcher, Cleanup) :-
594 setup_call_catcher_cleanup(Setup, Goal, Catcher,Cleanup).
604merge_set([], L, L) :- !.
605merge_set(L, [], L) :- !.
606merge_set([H1|T1], [H2|T2], [H1|R]) :- H1 @< H2, !, merge_set(T1, [H2|T2], R).
607merge_set([H1|T1], [H2|T2], [H2|R]) :- H1 @> H2, !, merge_set([H1|T1], T2, R).
608merge_set([H1|T1], [H2|T2], [H1|R]) :- H1 == H2, merge_set(T1, T2, R).
619merge([], L, L) :- !.
620merge(L, [], L) :- !.
621merge([H1|T1], [H2|T2], [H|R]) :-
622 ( H1 @=< H2
623 -> H = H1,
624 merge(T1, [H2|T2], R)
625 ; H = H2,
626 merge([H1|T1], T2, R)
627 ).
637index(Head) :-
638 print_message(warning, decl_no_effect(index(Head))).
645hash(PI) :-
646 print_message(warning, decl_no_effect(hash(PI))).
654set_base_module(M:Base) :-
655 set_module(M:base(Base)).
661eval_license :-
662 license.
668trie_insert_new(Trie, Term, Handle) :-
669 trie_insert(Trie, Term, [], Handle).
676thread_at_exit(Goal) :-
677 prolog_listen(this_thread_exit, Goal).
683read_history(Show, Help, Special, Prompt, Term, Bindings) :-
684 read_term_with_history(
685 Term,
686 [ show(Show),
687 help(Help),
688 no_save(Special),
689 prompt(Prompt),
690 variable_names(Bindings)
691 ]).
699'$sig_atomic'(Goal) :-
700 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.plandedinburgh.plfor more compatibility predicates.