2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: utils.yap *
|
|
|
|
* Last rev: 8/2/88 *
|
|
|
|
* mods: *
|
|
|
|
* comments: Some utility predicates available in yap *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
once(G) :- '$execute'(G), !.
|
|
|
|
|
2008-05-15 14:41:48 +01:00
|
|
|
forall(Cond, Action) :- \+((Cond, \+(Action))).
|
|
|
|
|
|
|
|
ignore(Goal) :- (Goal->true;true).
|
|
|
|
|
2008-02-12 17:03:59 +00:00
|
|
|
if(X,Y,Z) :-
|
|
|
|
yap_hacks:env_choice_point(CP0),
|
|
|
|
(
|
|
|
|
CP is '$last_choice_pt',
|
|
|
|
'$call'(X,CP,if(X,Y,Z),M),
|
|
|
|
'$execute'(X),
|
|
|
|
'$clean_ifcp'(CP),
|
|
|
|
'$call'(Y,CP,if(X,Y,Z),M)
|
|
|
|
;
|
|
|
|
'$call'(Z,CP,if(X,Y,Z),M)
|
|
|
|
).
|
2005-10-28 18:38:50 +01:00
|
|
|
|
|
|
|
call(X,A) :- '$execute'(X,A).
|
|
|
|
|
|
|
|
call(X,A1,A2) :- '$execute'(X,A1,A2).
|
|
|
|
|
|
|
|
call(X,A1,A2,A3) :- '$execute'(X,A1,A2,A3).
|
2001-04-24 17:40:11 +01:00
|
|
|
|
2006-12-31 12:29:46 +00:00
|
|
|
call(X,A1,A2,A3,A4) :- '$execute'(X,A1,A2,A3,A4).
|
|
|
|
|
|
|
|
call(X,A1,A2,A3,A4,A5) :- '$execute'(X,A1,A2,A3,A4,A5).
|
|
|
|
|
|
|
|
call(X,A1,A2,A3,A4,A5,A6) :- '$execute'(X,A1,A2,A3,A4,A5,A6).
|
|
|
|
|
|
|
|
call(X,A1,A2,A3,A4,A5,A6,A7) :- '$execute'(X,A1,A2,A3,A4,A5,A6,A7).
|
|
|
|
|
|
|
|
call(X,A1,A2,A3,A4,A5,A6,A7,A8) :- '$execute'(X,A1,A2,A3,A4,A5,A6,A7,A8).
|
|
|
|
|
|
|
|
call(X,A1,A2,A3,A4,A5,A6,A7,A8,A9) :- '$execute'(X,A1,A2,A3,A4,A5,A6,A7,A8,A9).
|
|
|
|
|
|
|
|
call(X,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10) :- '$execute'(X,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10).
|
|
|
|
|
|
|
|
call(X,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11) :- '$execute'(X,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11).
|
|
|
|
|
2006-12-30 03:25:47 +00:00
|
|
|
call_cleanup(Goal, Cleanup) :-
|
2009-05-20 15:29:13 +01:00
|
|
|
setup_call_catcher_cleanup(true, Goal, _Catcher, Cleanup).
|
|
|
|
|
|
|
|
call_cleanup(Goal, Catcher, Cleanup) :-
|
|
|
|
setup_call_catcher_cleanup(true, Goal, Catcher, Cleanup).
|
2006-12-30 03:25:47 +00:00
|
|
|
|
2009-05-20 07:53:14 +01:00
|
|
|
setup_call_cleanup(Setup, Goal, Cleanup) :-
|
|
|
|
setup_call_catcher_cleanup(Setup, Goal, Catcher, Cleanup).
|
|
|
|
|
|
|
|
setup_call_catcher_cleanup(Setup, Goal, Catcher, Cleanup) :-
|
2009-05-21 06:41:35 +01:00
|
|
|
yap_hacks:disable_interrupts,
|
2009-05-20 07:53:14 +01:00
|
|
|
'$do_setup'(Setup),
|
2009-06-03 01:46:41 +01:00
|
|
|
catch('$safe_call_cleanup'(Goal,Cleanup,Catcher,Exception),
|
2006-12-29 01:57:50 +00:00
|
|
|
Exception,
|
2007-01-07 11:27:09 +00:00
|
|
|
'$cleanup_exception'(Exception,Catcher,Cleanup)).
|
2006-12-29 01:57:50 +00:00
|
|
|
|
2009-05-20 07:53:14 +01:00
|
|
|
% this is simple, do nothing
|
|
|
|
'$do_setup'(A:true) :- atom(A), !.
|
|
|
|
% this is tricky: please don't forget that interrupts are disabled at this point
|
|
|
|
% and that they will only be enabled after setting up Cleanup
|
|
|
|
'$do_setup'(Setup) :-
|
|
|
|
(
|
|
|
|
yap_hacks:current_choice_point(CP0),
|
|
|
|
'$execute'(Setup),
|
|
|
|
yap_hacks:current_choice_point(CP1),
|
|
|
|
% are we looking at a deterministic goal?
|
|
|
|
% we don't need to care about enabling interrupts
|
|
|
|
(CP1 == CP0 -> ! ; true)
|
|
|
|
;
|
|
|
|
% reenable interrupts if Setup failed
|
2009-05-21 06:41:35 +01:00
|
|
|
yap_hacks:enable_interrupts,
|
2009-05-20 07:53:14 +01:00
|
|
|
fail
|
|
|
|
).
|
|
|
|
|
|
|
|
|
2007-05-27 22:40:17 +01:00
|
|
|
'$cleanup_exception'(Exception, exception(Exception), Cleanup) :- !,
|
2009-04-25 00:06:33 +01:00
|
|
|
% whatever happens, let exception go through
|
2009-06-03 01:46:41 +01:00
|
|
|
catch('$clean_call'(_,Cleanup),_,true),
|
2009-05-05 00:11:11 +01:00
|
|
|
throw(Exception).
|
2007-05-27 22:40:17 +01:00
|
|
|
'$cleanup_exception'(Exception, _, _) :-
|
|
|
|
throw(Exception).
|
2006-12-29 01:57:50 +00:00
|
|
|
|
2009-06-03 01:46:41 +01:00
|
|
|
'$safe_call_cleanup'(Goal, Cleanup, Catcher, Exception) :-
|
2009-05-20 07:53:14 +01:00
|
|
|
yap_hacks:current_choice_point(MyCP1),
|
2009-06-03 01:46:41 +01:00
|
|
|
'$freeze_goal'(Catcher, '$clean_call'(Exception, Cleanup)),
|
2009-05-05 00:11:11 +01:00
|
|
|
yap_hacks:trail_suspension_marker(Catcher),
|
2008-01-23 17:57:56 +00:00
|
|
|
(
|
2009-05-21 06:41:35 +01:00
|
|
|
yap_hacks:enable_interrupts,
|
2008-01-23 17:57:56 +00:00
|
|
|
yap_hacks:current_choice_point(CP0),
|
|
|
|
'$execute'(Goal),
|
2009-06-02 05:43:59 +01:00
|
|
|
% ensure environment for delayed variables in Goal
|
|
|
|
'$true',
|
2008-01-23 17:57:56 +00:00
|
|
|
yap_hacks:current_choice_point(CPF),
|
|
|
|
(
|
2009-06-03 01:46:41 +01:00
|
|
|
CP0 =:= CPF
|
|
|
|
->
|
|
|
|
Catcher = exit,
|
|
|
|
!
|
2008-01-23 17:57:56 +00:00
|
|
|
;
|
2009-06-03 01:46:41 +01:00
|
|
|
true
|
2008-01-23 17:57:56 +00:00
|
|
|
)
|
|
|
|
;
|
2009-06-03 01:46:41 +01:00
|
|
|
Catcher = fail,
|
|
|
|
fail
|
2006-12-29 01:57:50 +00:00
|
|
|
).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-01-23 17:57:56 +00:00
|
|
|
'$holds_true'.
|
|
|
|
|
2009-06-03 01:46:41 +01:00
|
|
|
% The first argument is used by JumpEnv to verify if a throw
|
|
|
|
% is going to be handled by the cleanup catcher. If it is so,
|
|
|
|
% clean_call will not be called from JumpToEnv.
|
|
|
|
'$clean_call'(_,Cleanup) :-
|
2007-01-07 13:47:23 +00:00
|
|
|
'$execute'(Cleanup), !.
|
2009-06-03 01:46:41 +01:00
|
|
|
'$clean_call'(_,_).
|
2006-12-31 01:50:35 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
op(P,T,V) :-
|
2008-02-13 10:15:36 +00:00
|
|
|
'$check_op'(P,T,V,op(P,T,V)),
|
|
|
|
'$op'(P, T, V).
|
|
|
|
|
|
|
|
'$check_op'(P,T,V,G) :-
|
|
|
|
(
|
|
|
|
var(P) ->
|
|
|
|
'$do_error'(instantiation_error,G)
|
|
|
|
;
|
|
|
|
var(T) ->
|
|
|
|
'$do_error'(instantiation_error,G)
|
|
|
|
;
|
|
|
|
var(V) ->
|
|
|
|
'$do_error'(instantiation_error,G)
|
|
|
|
;
|
|
|
|
\+ integer(P) ->
|
|
|
|
'$do_error'(type_error(integer,P),G)
|
|
|
|
;
|
|
|
|
\+ atom(T) ->
|
|
|
|
'$do_error'(type_error(atom,T),G)
|
|
|
|
;
|
|
|
|
P < 0 ->
|
|
|
|
'$do_error'(domain_error(out_of_range,P),G)
|
|
|
|
;
|
|
|
|
P > 1200 ->
|
|
|
|
'$do_error'(domain_error(out_of_range,P),G)
|
|
|
|
;
|
|
|
|
\+ '$associativity'(T) ->
|
2008-02-13 14:42:55 +00:00
|
|
|
'$do_error'(domain_error(operator_specifier,T),G)
|
2008-02-13 10:15:36 +00:00
|
|
|
;
|
|
|
|
'$check_op_name'(V,G)
|
|
|
|
).
|
|
|
|
|
|
|
|
'$associativity'(xfx).
|
|
|
|
'$associativity'(xfy).
|
2008-02-13 14:42:55 +00:00
|
|
|
'$associativity'(yfx).
|
2008-02-13 10:15:36 +00:00
|
|
|
'$associativity'(yfy).
|
|
|
|
'$associativity'(xf).
|
|
|
|
'$associativity'(yf).
|
|
|
|
'$associativity'(fx).
|
|
|
|
'$associativity'(fy).
|
|
|
|
|
|
|
|
'$check_op_name'(V,_) :-
|
|
|
|
atom(V), !.
|
|
|
|
'$check_op_name'(M:A, G) :-
|
|
|
|
(
|
|
|
|
var(M) ->
|
|
|
|
'$do_error'(instantiation_error,G)
|
|
|
|
;
|
|
|
|
var(A) ->
|
|
|
|
'$do_error'(instantiation_error,G)
|
|
|
|
;
|
|
|
|
\+ atom(A) ->
|
|
|
|
'$do_error'(instantiation_error,G)
|
|
|
|
;
|
|
|
|
\+ atom(M) ->
|
|
|
|
'$do_error'(instantiation_error,G)
|
|
|
|
;
|
|
|
|
true
|
|
|
|
).
|
|
|
|
'$check_op_name'([A|As], G) :-
|
|
|
|
'$check_op_name'(A, G),
|
|
|
|
'$check_op_names'(As, G).
|
|
|
|
|
|
|
|
'$check_op_names'([], _).
|
|
|
|
'$check_op_names'([A|As], G) :-
|
|
|
|
'$check_op_name'(A, G),
|
|
|
|
'$check_op_names'(As, G).
|
|
|
|
|
|
|
|
|
2008-02-15 12:41:33 +00:00
|
|
|
'$op'(P, T, [A|As]) :- !,
|
|
|
|
'$opl'(P, T, [A|As]).
|
2008-02-13 10:15:36 +00:00
|
|
|
'$op'(P, T, A) :-
|
2008-02-15 12:41:33 +00:00
|
|
|
'$op2'(P,T,A).
|
|
|
|
|
|
|
|
'$opl'(P, T, []).
|
|
|
|
'$opl'(P, T, [A|As]) :-
|
|
|
|
'$op2'(P, T, A),
|
|
|
|
'$opl'(P, T, As).
|
|
|
|
|
|
|
|
'$op2'(P,T,A) :-
|
2008-02-13 10:15:36 +00:00
|
|
|
atom(A), !,
|
|
|
|
'$opdec'(P,T,A,prolog).
|
2008-02-15 12:41:33 +00:00
|
|
|
'$op2'(P,T,A) :-
|
|
|
|
strip_module(A,M,N),
|
|
|
|
(M = user -> NM = prolog ; NM = M),
|
|
|
|
'$opdec'(P,T,N,NM).
|
2008-02-13 10:15:36 +00:00
|
|
|
|
|
|
|
current_op(X,Y,V) :- var(V), !,
|
|
|
|
'$current_module'(M),
|
|
|
|
V = M:Z,
|
|
|
|
'$do_current_op'(X,Y,Z,M).
|
|
|
|
current_op(X,Y,M:Z) :- !,
|
|
|
|
'$current_opm'(X,Y,Z,M).
|
|
|
|
current_op(X,Y,Z) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$do_current_op'(X,Y,Z,M).
|
|
|
|
|
|
|
|
|
|
|
|
'$current_opm'(X,Y,Z,M) :-
|
|
|
|
var(Z), !,
|
|
|
|
'$do_current_op'(X,Y,Z,M).
|
|
|
|
'$current_opm'(X,Y,M:Z,_) :- !,
|
|
|
|
'$current_opm'(X,Y,Z,M).
|
|
|
|
'$current_opm'(X,Y,Z,M) :-
|
|
|
|
'$do_current_op'(X,Y,Z,M).
|
|
|
|
|
|
|
|
'$do_current_op'(X,Y,Z,M) :-
|
|
|
|
'$current_op'(X,Y,Z,M1),
|
|
|
|
( M1 = prolog -> true ; M1 = M ).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
%%% Operating System utilities
|
|
|
|
|
|
|
|
unix(V) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,unix(V)).
|
2002-03-04 15:55:13 +00:00
|
|
|
unix(argv(L)) :- '$is_list_of_atoms'(L,L), !, '$argv'(L).
|
2001-04-09 20:54:03 +01:00
|
|
|
unix(argv(V)) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(atomic,V),unix(argv(V))).
|
2001-04-09 20:54:03 +01:00
|
|
|
unix(cd) :- cd('~').
|
|
|
|
unix(cd(V)) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,unix(cd(V))).
|
2001-04-09 20:54:03 +01:00
|
|
|
unix(cd(A)) :- atomic(A), !, cd(A).
|
|
|
|
unix(cd(V)) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(atomic,V),unix(cd(V))).
|
2002-01-14 22:26:53 +00:00
|
|
|
unix(environ(X,Y)) :- '$do_environ'(X,Y).
|
2001-04-09 20:54:03 +01:00
|
|
|
unix(getcwd(X)) :- getcwd(X).
|
|
|
|
unix(shell(V)) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,unix(shell(V))).
|
2005-11-23 13:24:00 +00:00
|
|
|
unix(shell(A)) :- atom(A), !, '$shell'(A).
|
2001-04-09 20:54:03 +01:00
|
|
|
unix(shell(V)) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(atomic,V),unix(shell(V))).
|
2001-04-09 20:54:03 +01:00
|
|
|
unix(system(V)) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,unix(system(V))).
|
2005-11-23 13:24:00 +00:00
|
|
|
unix(system(A)) :- atom(A), !, system(A).
|
2001-04-09 20:54:03 +01:00
|
|
|
unix(system(V)) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(atom,V),unix(system(V))).
|
2001-04-09 20:54:03 +01:00
|
|
|
unix(shell) :- sh.
|
|
|
|
unix(putenv(X,Y)) :- '$putenv'(X,Y).
|
|
|
|
|
2002-01-14 22:26:53 +00:00
|
|
|
|
2002-03-04 15:55:13 +00:00
|
|
|
'$is_list_of_atoms'(V,_) :- var(V),!.
|
|
|
|
'$is_list_of_atoms'([],_) :- !.
|
|
|
|
'$is_list_of_atoms'([H|L],L0) :- !,
|
|
|
|
'$check_if_head_may_be_atom'(H,L0),
|
|
|
|
'$is_list_of_atoms'(L,L0).
|
|
|
|
'$is_list_of_atoms'(H,L0) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(list,H),unix(argv(L0))).
|
2002-03-04 15:55:13 +00:00
|
|
|
|
2006-03-24 16:26:31 +00:00
|
|
|
'$check_if_head_may_be_atom'(H,_) :-
|
2002-03-04 15:55:13 +00:00
|
|
|
var(H), !.
|
2006-03-24 16:26:31 +00:00
|
|
|
'$check_if_head_may_be_atom'(H,_) :-
|
2002-03-04 15:55:13 +00:00
|
|
|
atom(H), !.
|
|
|
|
'$check_if_head_may_be_atom'(H,L0) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(atom,H),unix(argv(L0))).
|
2002-03-04 15:55:13 +00:00
|
|
|
|
|
|
|
|
2002-01-14 22:26:53 +00:00
|
|
|
'$do_environ'(X, Y) :-
|
|
|
|
var(X), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,unix(environ(X,Y))).
|
2002-01-14 22:26:53 +00:00
|
|
|
'$do_environ'(X, Y) :- atom(X), !,
|
|
|
|
'$getenv'(X,Y).
|
|
|
|
'$do_environ'(X, Y) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(atom,X),unix(environ(X,Y))).
|
2002-01-14 22:26:53 +00:00
|
|
|
|
|
|
|
|
2001-05-21 21:00:05 +01:00
|
|
|
putenv(Na,Val) :-
|
|
|
|
'$putenv'(Na,Val).
|
|
|
|
|
|
|
|
getenv(Na,Val) :-
|
|
|
|
'$getenv'(Na,Val).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
%%% Saving and restoring a computation
|
|
|
|
|
|
|
|
save(A) :- var(A), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,save(A)).
|
2001-04-09 20:54:03 +01:00
|
|
|
save(A) :- atom(A), !, name(A,S), '$save'(S).
|
|
|
|
save(S) :- '$save'(S).
|
|
|
|
|
|
|
|
save(A,_) :- var(A), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,save(A)).
|
2001-04-09 20:54:03 +01:00
|
|
|
save(A,OUT) :- atom(A), !, name(A,S), '$save'(S,OUT).
|
|
|
|
save(S,OUT) :- '$save'(S,OUT).
|
|
|
|
|
|
|
|
save_program(A) :- var(A), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,save_program(A)).
|
2001-04-09 20:54:03 +01:00
|
|
|
save_program(A) :- atom(A), !, name(A,S), '$save_program'(S).
|
|
|
|
save_program(S) :- '$save_program'(S).
|
|
|
|
|
|
|
|
save_program(A, G) :- var(A), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,save_program(A,G)).
|
2001-04-09 20:54:03 +01:00
|
|
|
save_program(A, G) :- var(G), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,save_program(A,G)).
|
2001-04-09 20:54:03 +01:00
|
|
|
save_program(A, G) :- \+ callable(G), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(callable,G),save_program(A,G)).
|
2001-04-09 20:54:03 +01:00
|
|
|
save_program(A, G) :-
|
|
|
|
( atom(A) -> name(A,S) ; A = S),
|
2003-08-27 14:37:10 +01:00
|
|
|
recorda('$restore_goal',G,R),
|
2001-04-09 20:54:03 +01:00
|
|
|
'$save_program'(S),
|
|
|
|
erase(R),
|
|
|
|
fail.
|
|
|
|
save_program(_,_).
|
|
|
|
|
|
|
|
restore(A) :- var(A), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,restore(A)).
|
2001-04-09 20:54:03 +01:00
|
|
|
restore(A) :- atom(A), !, name(A,S), '$restore'(S).
|
|
|
|
restore(S) :- '$restore'(S).
|
|
|
|
|
2003-11-12 12:33:31 +00:00
|
|
|
%%% current ....
|
|
|
|
|
2004-12-08 04:45:04 +00:00
|
|
|
recordaifnot(K,T,R) :-
|
|
|
|
recorded(K,T,R), % force non-det binding to R.
|
|
|
|
'$still_variant'(R,T),
|
|
|
|
!,
|
|
|
|
fail.
|
|
|
|
recordaifnot(K,T,R) :-
|
|
|
|
recorda(K,T,R).
|
|
|
|
|
2003-11-12 12:33:31 +00:00
|
|
|
recordzifnot(K,T,R) :-
|
|
|
|
recorded(K,T,R),
|
|
|
|
'$still_variant'(R,T),
|
|
|
|
!,
|
|
|
|
fail.
|
|
|
|
recordzifnot(K,T,R) :-
|
|
|
|
recordz(K,T,R).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
current_atom(A) :- % check
|
|
|
|
atom(A), !.
|
|
|
|
current_atom(A) :- % generate
|
|
|
|
'$current_atom'(A).
|
2006-11-27 17:42:03 +00:00
|
|
|
current_atom(A) :- % generate
|
|
|
|
'$current_wide_atom'(A).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
%%% The unknown predicate,
|
|
|
|
% informs about what the user wants to be done when
|
|
|
|
% there are no clauses for a certain predicate */
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
unknown(V0,V) :-
|
|
|
|
'$current_module'(M),
|
|
|
|
'$unknown'(V0,V,M).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
% query mode
|
2001-11-15 00:01:43 +00:00
|
|
|
'$unknown'(V0,V,_) :- var(V), !,
|
2001-04-09 20:54:03 +01:00
|
|
|
'$ask_unknown_flag'(V),
|
|
|
|
V = V0.
|
|
|
|
% handle modules.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$unknown'(V0,Mod:Handler,_) :-
|
|
|
|
'$unknown'(V0,Handler,Mod).
|
2001-04-09 20:54:03 +01:00
|
|
|
% check if we have one we like.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$unknown'(_,New,Mod) :-
|
|
|
|
'$valid_unknown_handler'(New,Mod), fail.
|
2001-04-09 20:54:03 +01:00
|
|
|
% clean up previous unknown predicate handlers
|
2001-11-15 00:01:43 +00:00
|
|
|
'$unknown'(Old,New,Mod) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
recorded('$unknown','$unknown'(_,MyOld),Ref), !,
|
2001-04-09 20:54:03 +01:00
|
|
|
erase(Ref),
|
|
|
|
'$cleanup_unknown_handler'(MyOld,Old),
|
2001-11-15 00:01:43 +00:00
|
|
|
'$new_unknown'(New, Mod).
|
2001-04-09 20:54:03 +01:00
|
|
|
% store the new one.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$unknown'(fail,New,Mod) :-
|
|
|
|
'$new_unknown'(New, Mod).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$valid_unknown_handler'(V,_) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,yap_flag(unknown,V)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$valid_unknown_handler'(fail,_) :- !.
|
|
|
|
'$valid_unknown_handler'(error,_) :- !.
|
|
|
|
'$valid_unknown_handler'(warning,_) :- !.
|
|
|
|
'$valid_unknown_handler'(S,M) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
functor(S,_,1),
|
|
|
|
arg(1,S,A),
|
|
|
|
var(A),
|
2001-11-15 00:01:43 +00:00
|
|
|
\+ '$undefined'(S,M),
|
2001-04-09 20:54:03 +01:00
|
|
|
!.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$valid_unknown_handler'(S,_) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(domain_error(flag_value,unknown+S),yap_flag(unknown,S)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-12-18 17:12:33 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$ask_unknown_flag'(Old) :-
|
2009-05-06 15:33:13 +01:00
|
|
|
recorded('$unknown','$unknown'(_,MyOld),_), !,
|
|
|
|
'$cleanup_unknown_handler'(MyOld,Old).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$ask_unknown_flag'(fail).
|
|
|
|
|
|
|
|
'$cleanup_unknown_handler'('$unknown_error'(_),error) :- !.
|
|
|
|
'$cleanup_unknown_handler'('$unknown_warning'(_),warning) :- !.
|
|
|
|
'$cleanup_unknown_handler'(Handler, Handler).
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$new_unknown'(fail,_) :- !.
|
|
|
|
'$new_unknown'(error,_) :- !,
|
2003-08-27 14:37:10 +01:00
|
|
|
recorda('$unknown','$unknown'(P,'$unknown_error'(P)),_).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$new_unknown'(warning,_) :- !,
|
2003-08-27 14:37:10 +01:00
|
|
|
recorda('$unknown','$unknown'(P,'$unknown_warning'(P)),_).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$new_unknown'(X,M) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
arg(1,X,A),
|
2003-08-27 14:37:10 +01:00
|
|
|
recorda('$unknown','$unknown'(A,M:X),_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-10-29 02:28:37 +01:00
|
|
|
'$unknown_error'(Mod:Goal) :-
|
|
|
|
functor(Goal,Name,Arity),
|
|
|
|
'$program_continuation'(PMod,PName,PAr),
|
|
|
|
'$do_error'(existence_error(procedure,Name/Arity),context(Mod:Goal,PMod:PName/PAr)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-12-18 17:12:33 +00:00
|
|
|
'$unknown_warning'(Mod:Goal) :-
|
|
|
|
functor(Goal,Name,Arity),
|
|
|
|
'$program_continuation'(PMod,PName,PAr),
|
2008-02-22 15:08:37 +00:00
|
|
|
print_message(error,error(existence_error(procedure,Name/Arity), context(Mod:Goal,PMod:PName/PAr))),
|
2001-04-09 20:54:03 +01:00
|
|
|
fail.
|
|
|
|
|
|
|
|
%%% Some "dirty" predicates
|
|
|
|
|
|
|
|
% Only efective if yap compiled with -DDEBUG
|
|
|
|
% this predicate shows the code produced by the compiler
|
2006-12-29 01:57:50 +00:00
|
|
|
'$show_code' :- '$debug'(0'f). %' just make emacs happy
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
grow_heap(X) :- '$grow_heap'(X).
|
|
|
|
grow_stack(X) :- '$grow_stack'(X).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
%
|
|
|
|
% gc() expects to be called from "call". Make sure it has an
|
|
|
|
% environment to return to.
|
|
|
|
%
|
|
|
|
%garbage_collect :- save(dump), '$gc', save(dump2).
|
2001-10-03 14:39:16 +01:00
|
|
|
garbage_collect :-
|
|
|
|
'$gc'.
|
|
|
|
gc :-
|
|
|
|
yap_flag(gc,on).
|
|
|
|
nogc :-
|
|
|
|
yap_flag(gc,off).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-06-04 19:21:55 +01:00
|
|
|
garbage_collect_atoms :-
|
|
|
|
'$atom_gc'.
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$force_environment_for_gc'.
|
|
|
|
|
|
|
|
'$good_list_of_character_codes'(V) :- var(V), !.
|
|
|
|
'$good_list_of_character_codes'([]).
|
|
|
|
'$good_list_of_character_codes'([X|L]) :-
|
|
|
|
'$good_character_code'(X),
|
|
|
|
'$good_list_of_character_codes'(L).
|
|
|
|
|
|
|
|
'$good_character_code'(X) :- var(X), !.
|
|
|
|
'$good_character_code'(X) :- integer(X), X > -2, X < 256.
|
|
|
|
|
|
|
|
atom_concat(X,Y,At) :-
|
2005-01-31 17:47:57 +00:00
|
|
|
(
|
|
|
|
nonvar(X), nonvar(Y)
|
|
|
|
->
|
|
|
|
atom_concat([X,Y],At)
|
|
|
|
;
|
|
|
|
atom(At) ->
|
|
|
|
atom_length(At,Len),
|
|
|
|
'$atom_contact_split'(At,0,Len,X,Y)
|
|
|
|
;
|
|
|
|
var(At) ->
|
|
|
|
'$do_error'(instantiation_error,atom_concat(X,Y,At))
|
|
|
|
;
|
|
|
|
'$do_error'(type_error(atom,At),atomic_concant(X,Y,At))
|
|
|
|
).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-08-11 17:14:55 +01:00
|
|
|
atomic_concat(X,Y,At) :-
|
2005-01-31 17:47:57 +00:00
|
|
|
(
|
|
|
|
nonvar(X), nonvar(Y)
|
|
|
|
->
|
|
|
|
atomic_concat([X,Y],At)
|
|
|
|
;
|
|
|
|
atom(At) ->
|
|
|
|
atom_length(At,Len),
|
|
|
|
'$atom_contact_split'(At,0,Len,X,Y)
|
|
|
|
;
|
|
|
|
number(At) ->
|
|
|
|
number_codes(At,Codes),
|
2008-03-12 16:26:51 +00:00
|
|
|
lists:append(X0,Y0,Codes),
|
2005-01-31 17:47:57 +00:00
|
|
|
name(X,X0),
|
|
|
|
name(Y,Y0)
|
|
|
|
;
|
|
|
|
var(At) ->
|
|
|
|
'$do_error'(instantiation_error,atomic_concat(X,Y,At))
|
|
|
|
;
|
|
|
|
'$do_error'(type_error(atomic,At),atomic_concant(X,Y,At))
|
|
|
|
).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$atom_contact_split'(At,Len,Len,X,Y) :- !,
|
|
|
|
'$atom_split'(At,Len,X,Y).
|
|
|
|
'$atom_contact_split'(At,Len1,_,X,Y) :-
|
|
|
|
'$atom_split'(At,Len1,X,Y).
|
|
|
|
'$atom_contact_split'(At,Len1,Len,X,Y) :-
|
|
|
|
Len2 is Len1+1,
|
|
|
|
'$atom_contact_split'(At,Len2,Len,X,Y).
|
|
|
|
|
2007-10-09 00:02:16 +01:00
|
|
|
sub_atom(At, Bef, Size, After, SubAt) :-
|
|
|
|
% extract something from an atom
|
|
|
|
atom(At), integer(Bef), integer(Size), !,
|
|
|
|
'$sub_atom_extract'(At, Bef, Size, After, SubAt).
|
2009-06-22 21:35:40 +01:00
|
|
|
sub_atom(At, Bef, Size, After, SubAt) :-
|
|
|
|
% extract subatom from an atom
|
|
|
|
atom(At), atom(SubAt), !,
|
|
|
|
'$do_sub_atom_fetch'(At, Bef, Size, After, SubAt, 0).
|
2003-11-18 19:08:38 +00:00
|
|
|
sub_atom(At, Bef, Size, After, SubAt) :-
|
|
|
|
atom(At), !,
|
|
|
|
atom_codes(At, Atl),
|
|
|
|
'$sub_atom2'(Bef, Atl, Size, After, SubAt, sub_atom(At, Bef, Size, After, SubAt)).
|
2001-04-09 20:54:03 +01:00
|
|
|
sub_atom(At, Bef, Size, After, SubAt) :-
|
|
|
|
var(At), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,sub_atom(At, Bef, Size,After, SubAt)).
|
2001-04-09 20:54:03 +01:00
|
|
|
sub_atom(At, Bef, Size, After, SubAt) :-
|
|
|
|
\+ atom(At), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(atom,At),sub_atom(At, Bef, Size,After, SubAt)).
|
2003-11-18 19:08:38 +00:00
|
|
|
|
|
|
|
|
2009-06-22 21:35:40 +01:00
|
|
|
'$do_sub_atom_fetch'(At, Bef, Size, After, SubAt, I0) :-
|
|
|
|
'$sub_atom_fetch'(At, Bef1, Size, After1, SubAt, I0),
|
|
|
|
(
|
|
|
|
Bef = Bef1, After = After1
|
|
|
|
;
|
|
|
|
Next is Bef1+1,
|
|
|
|
'$do_sub_atom_fetch'(At, Bef, Size, After, SubAt, Next)
|
|
|
|
).
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-18 19:08:38 +00:00
|
|
|
'$sub_atom2'(Bef, Atl, Size, After, SubAt, ErrorTerm) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
var(Bef), !,
|
2003-11-18 19:08:38 +00:00
|
|
|
'$sub_atombv'(Bef, Size, After, SubAt, Atl, ErrorTerm).
|
|
|
|
'$sub_atom2'(Bef, Atl, Size, After, SubAt, ErrorTerm) :-
|
|
|
|
'$sub_atom_get_subchars'(Bef, Atl, NewAtl),
|
|
|
|
'$sub_atom3'(Size, After, SubAt, NewAtl, ErrorTerm).
|
|
|
|
|
|
|
|
% if SubAt is bound, the rest is deterministic.
|
|
|
|
'$sub_atom3'(Size, After, SubAt, Atl, ErrorTerm) :-
|
|
|
|
nonvar(SubAt), !,
|
|
|
|
'$sub_atom_needs_atom'(SubAt,ErrorTerm),
|
|
|
|
'$sub_atom_needs_int'(Size,ErrorTerm),
|
|
|
|
'$sub_atom_needs_int'(After,ErrorTerm),
|
|
|
|
atom_codes(SubAt,Atls),
|
|
|
|
'$$_length1'(Atls, 0, Size),
|
|
|
|
'$sub_atom_get_subchars_and_match'(Size, Atl, Atls, NAtl),
|
|
|
|
'$$_length1'(NAtl,0,After).
|
|
|
|
% SubAt is unbound, but Size is bound
|
|
|
|
'$sub_atom3'(Size, After, SubAt, Atl, ErrorTerm) :-
|
|
|
|
nonvar(Size), !,
|
|
|
|
'$sub_atom_needs_int'(Size,ErrorTerm),
|
|
|
|
'$sub_atom_needs_int'(After,ErrorTerm),
|
|
|
|
'$sub_atom_get_subchars_and_match'(Size, Atl, SubAts, NAtl),
|
|
|
|
'$$_length1'(NAtl,0,After),
|
|
|
|
atom_codes(SubAt,SubAts).
|
|
|
|
% SubAt and Size are unbound, but After is bound.
|
|
|
|
'$sub_atom3'(Size, After, SubAt, Atl, ErrorTerm) :-
|
|
|
|
nonvar(After), !,
|
|
|
|
'$sub_atom_needs_int'(After,ErrorTerm),
|
|
|
|
'$sub_atom_get_last_subchars'(Atl,SubAts,After,Total,Size),
|
|
|
|
Total >= After,
|
|
|
|
atom_codes(SubAt,SubAts).
|
|
|
|
% SubAt, Size, and After are unbound.
|
2006-03-24 16:26:31 +00:00
|
|
|
'$sub_atom3'(Size, After, SubAt, Atl, _) :-
|
2003-11-18 19:08:38 +00:00
|
|
|
'$$_length1'(Atl,0,Len),
|
|
|
|
'$sub_atom_split'(Atl,Len,SubAts,Size,_,After),
|
|
|
|
atom_codes(SubAt,SubAts).
|
|
|
|
|
|
|
|
% Bef is unbound, so we've got three hypothesis
|
|
|
|
% ok: in the best case we just try to find SubAt in the original atom.
|
|
|
|
'$sub_atombv'(Bef, Size, After, SubAt, Atl, ErrorTerm) :-
|
|
|
|
nonvar(SubAt), !,
|
|
|
|
'$sub_atom_needs_atom'(SubAt, ErrorTerm),
|
|
|
|
atom_codes(SubAt,SubAts),
|
|
|
|
'$sub_atom_search'(SubAts, Atl, 0, Bef, AfterS),
|
|
|
|
'$$_length1'(SubAts, 0, Size),
|
|
|
|
'$$_length1'(AfterS, 0, After).
|
|
|
|
% ok: in the second best case we just get rid of the tail
|
|
|
|
'$sub_atombv'(Bef, Size, After, SubAt, Atl, ErrorTerm) :-
|
|
|
|
nonvar(After), !,
|
|
|
|
'$sub_atom_needs_int'(After, ErrorTerm),
|
|
|
|
'$sub_atom_get_last_subchars'(Atl,SubAt0,After,Total,Size0),
|
|
|
|
Total >= After,
|
|
|
|
'$sub_atom_split'(SubAt0,Size0,_,Bef,SubAts,Size),
|
|
|
|
atom_codes(SubAt,SubAts).
|
|
|
|
% ok: just do everything
|
2006-03-24 16:26:31 +00:00
|
|
|
'$sub_atombv'(Bef, Size, After, SubAt, Atl, _) :-
|
2003-11-18 19:08:38 +00:00
|
|
|
'$$_length1'(Atl, 0, Len),
|
|
|
|
'$sub_atom_split'(Atl,Len,_,Bef,Atls2,Len2),
|
|
|
|
'$sub_atom_split'(Atls2,Len2,SubAts,Size,_,After),
|
|
|
|
atom_codes(SubAt,SubAts).
|
|
|
|
|
|
|
|
'$sub_atom_search'([], AfterS, BefSize, BefSize, AfterS).
|
|
|
|
'$sub_atom_search'([C|SubAts], [C|Atl], BefSize, BefSize, AfterS) :-
|
|
|
|
'$sub_atom_search2'(SubAts, Atl, AfterS).
|
|
|
|
'$sub_atom_search'([C|SubAts], [_|Atl], BefSize, BefSizeF, AfterS) :-
|
|
|
|
NBefSize is BefSize+1,
|
|
|
|
'$sub_atom_search'([C|SubAts], Atl, NBefSize, BefSizeF, AfterS).
|
|
|
|
|
|
|
|
'$sub_atom_search2'([], AfterS, AfterS).
|
|
|
|
'$sub_atom_search2'([C|SubAts], [C|Atl], AfterS) :-
|
|
|
|
'$sub_atom_search2'(SubAts, Atl, AfterS).
|
|
|
|
|
|
|
|
'$sub_atom_get_subchars'(0, Atl, Atl) :- !.
|
|
|
|
'$sub_atom_get_subchars'(I0, [_|Atl], NAtl) :-
|
|
|
|
I is I0-1,
|
|
|
|
'$sub_atom_get_subchars'(I, Atl, NAtl).
|
|
|
|
|
|
|
|
'$sub_atom_get_subchars'(0, Atl, [], Atl) :- !.
|
|
|
|
'$sub_atom_get_subchars'(I0, [C|Atl], [C|L], NAtl) :-
|
|
|
|
I is I0-1,
|
|
|
|
'$sub_atom_get_subchars'(I, Atl, L, NAtl).
|
|
|
|
|
|
|
|
'$sub_atom_get_subchars_and_match'(0, Atl, [], Atl) :- !.
|
|
|
|
'$sub_atom_get_subchars_and_match'(I0, [C|Atl], [C|Match], NAtl) :-
|
|
|
|
I is I0-1,
|
|
|
|
'$sub_atom_get_subchars_and_match'(I, Atl, Match, NAtl).
|
|
|
|
|
|
|
|
'$sub_atom_check_length'([],0).
|
|
|
|
'$sub_atom_check_length'([_|L],N1) :-
|
|
|
|
N1 > 0,
|
|
|
|
N is N1-1,
|
|
|
|
'$sub_atom_check_length'(L,N).
|
|
|
|
|
2006-03-24 16:26:31 +00:00
|
|
|
'$sub_atom_get_last_subchars'([],[],_,0,0).
|
2003-11-18 19:08:38 +00:00
|
|
|
'$sub_atom_get_last_subchars'([C|Atl],SubAt,After,Total,Size) :-
|
|
|
|
'$sub_atom_get_last_subchars'(Atl,SubAt0,After,Total0,Size0),
|
|
|
|
Total is Total0+1,
|
|
|
|
( Total > After ->
|
|
|
|
Size is Size0+1, SubAt = [C|SubAt0]
|
|
|
|
;
|
|
|
|
Size = Size0, SubAt = SubAt0
|
|
|
|
).
|
|
|
|
|
|
|
|
'$sub_atom_split'(Atl,After,[],0,Atl,After).
|
|
|
|
'$sub_atom_split'([C|Atl],Len,[C|Atls],Size,NAtl,After) :-
|
|
|
|
Len1 is Len-1,
|
|
|
|
'$sub_atom_split'(Atl,Len1,Atls,Size0,NAtl,After),
|
|
|
|
Size is Size0+1.
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-11-18 19:08:38 +00:00
|
|
|
'$sub_atom_needs_int'(V,_) :- var(V), !.
|
2007-10-05 19:24:30 +01:00
|
|
|
'$sub_atom_needs_int'(I,_) :- integer(I), I >= 0, !.
|
2003-11-18 19:08:38 +00:00
|
|
|
'$sub_atom_needs_int'(I,ErrorTerm) :- integer(I), !,
|
|
|
|
'$do_error'(domain_error(not_less_than_zero,I),ErrorTerm).
|
|
|
|
'$sub_atom_needs_int'(I,ErrorTerm) :-
|
|
|
|
'$do_error'(type_error(integer,I),ErrorTerm).
|
|
|
|
|
|
|
|
'$sub_atom_needs_atom'(V,_) :- var(V), !.
|
2006-03-24 16:26:31 +00:00
|
|
|
'$sub_atom_needs_atom'(A,_) :- atom(A), !.
|
2003-11-18 19:08:38 +00:00
|
|
|
'$sub_atom_needs_atom'(A,ErrorTerm) :-
|
|
|
|
'$do_error'(type_error(atom,A),ErrorTerm).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
'$singletons_in_term'(T,VL) :-
|
|
|
|
'$variables_in_term'(T,[],V10),
|
|
|
|
'$sort'(V10, V1),
|
|
|
|
'$non_singletons_in_term'(T,[],V20),
|
|
|
|
'$sort'(V20, V2),
|
|
|
|
'$subtract_lists_of_variables'(V2,V1,VL).
|
|
|
|
|
|
|
|
'$subtract_lists_of_variables'([],VL,VL).
|
|
|
|
'$subtract_lists_of_variables'([_|_],[],[]) :- !.
|
|
|
|
'$subtract_lists_of_variables'([V1|VL1],[V2|VL2],VL) :-
|
|
|
|
V1 == V2, !,
|
|
|
|
'$subtract_lists_of_variables'(VL1,VL2,VL).
|
|
|
|
'$subtract_lists_of_variables'([V1|VL1],[V2|VL2],[V2|VL]) :-
|
|
|
|
'$subtract_lists_of_variables'([V1|VL1],VL2,VL).
|
|
|
|
|
|
|
|
simple(V) :- var(V), !.
|
|
|
|
simple(A) :- atom(A), !.
|
|
|
|
simple(N) :- number(N).
|
|
|
|
|
|
|
|
callable(V) :- var(V), !, fail.
|
|
|
|
callable(V) :- atom(V), !.
|
|
|
|
callable(V) :- functor(V,_,Ar), Ar > 0.
|
|
|
|
|
|
|
|
initialization :-
|
|
|
|
'$initialisation_goals'.
|
|
|
|
|
|
|
|
prolog_initialization(G) :- var(G), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,initialization(G)).
|
2001-04-09 20:54:03 +01:00
|
|
|
prolog_initialization(T) :- callable(T), !,
|
|
|
|
'$assert_init'(T).
|
|
|
|
prolog_initialization(T) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(callable,T),initialization(T)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
'$assert_init'(T) :- recordz('$startup_goal',T,_), fail.
|
2001-04-09 20:54:03 +01:00
|
|
|
'$assert_init'(_).
|
|
|
|
|
|
|
|
version :- '$version'.
|
|
|
|
|
|
|
|
version(V) :- var(V), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,version(V)).
|
2001-04-09 20:54:03 +01:00
|
|
|
version(T) :- atom(T), !, '$assert_version'(T).
|
|
|
|
version(T) :-
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(type_error(atom,T),version(T)).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
'$assert_version'(T) :- recordz('$version',T,_), fail.
|
2001-04-09 20:54:03 +01:00
|
|
|
'$assert_version'(_).
|
|
|
|
|
|
|
|
'$set_toplevel_hook'(_) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
recorded('$toplevel_hooks',_,R),
|
2001-04-09 20:54:03 +01:00
|
|
|
erase(R),
|
|
|
|
fail.
|
|
|
|
'$set_toplevel_hook'(H) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
recorda('$toplevel_hooks',H,_),
|
2001-04-09 20:54:03 +01:00
|
|
|
fail.
|
|
|
|
'$set_toplevel_hook'(_).
|
2004-04-27 16:14:38 +01:00
|
|
|
|
|
|
|
halt(X) :- '$halt'(X).
|
|
|
|
|
|
|
|
halt :-
|
2008-02-22 15:08:37 +00:00
|
|
|
print_message(informational, halt),
|
2004-04-27 16:14:38 +01:00
|
|
|
'$halt'(0).
|
|
|
|
|
|
|
|
halt(X) :-
|
|
|
|
'$halt'(X).
|
|
|
|
|
2005-05-25 19:58:38 +01:00
|
|
|
nth_instance(X,Y,Z) :-
|
|
|
|
nonvar(X), var(Y), var(Z), !,
|
|
|
|
recorded(X,_,Z),
|
|
|
|
'$nth_instance'(_,Y,Z).
|
|
|
|
nth_instance(X,Y,Z) :-
|
|
|
|
'$nth_instance'(X,Y,Z).
|
|
|
|
|
2005-10-21 17:09:03 +01:00
|
|
|
'$run_atom_goal'(GA) :-
|
|
|
|
'$current_module'(Module),
|
2007-05-20 12:27:37 +01:00
|
|
|
atom_codes(GA,Gs0),
|
|
|
|
'$add_dot_to_atom_goal'(Gs0,Gs),
|
2005-10-21 17:09:03 +01:00
|
|
|
charsio:open_mem_read_stream(Gs, Stream),
|
|
|
|
( '$system_catch'(read(Stream, G),Module,_,fail) ->
|
|
|
|
close(Stream)
|
|
|
|
;
|
|
|
|
close(Stream),
|
|
|
|
fail
|
|
|
|
),
|
|
|
|
'$system_catch'('$query'(once(G), []),Module,Error,user:'$Error'(Error)).
|
2005-11-26 02:57:25 +00:00
|
|
|
|
2009-05-21 06:41:35 +01:00
|
|
|
'$add_dot_to_atom_goal'([],[0'.]) :- !. %'
|
2007-05-20 12:27:37 +01:00
|
|
|
'$add_dot_to_atom_goal'([0'.],[0'.]) :- !.
|
|
|
|
'$add_dot_to_atom_goal'([C|Gs0],[C|Gs]) :-
|
|
|
|
'$add_dot_to_atom_goal'(Gs0,Gs).
|
|
|
|
|
|
|
|
|
2005-11-26 02:57:25 +00:00
|
|
|
prolog_current_frame(Env) :-
|
2007-01-24 14:20:04 +00:00
|
|
|
Env is '$env'.
|
2005-11-26 02:57:25 +00:00
|
|
|
|
2007-02-21 16:50:51 +00:00
|
|
|
nb_current(GlobalVariable, Val) :-
|
|
|
|
var(GlobalVariable), !,
|
|
|
|
'$nb_current'(GlobalVariable),
|
|
|
|
nb_getval(GlobalVariable, Val).
|
|
|
|
nb_current(GlobalVariable, Val) :-
|
|
|
|
nb_getval(GlobalVariable, Val).
|
|
|
|
|