|
264 | 264 | as_p1_exec(ispeEn(ERet,ECode,_),ERet) :- !, call(ECode).
|
265 | 265 | as_p1_exec(ispeEnN(ERet,ECode,_,_),ERet) :- !, call(ECode).
|
266 | 266 | as_p1_exec(ispeEnNC(ERet,ECode,_,_,CCode),ERet) :- !, call(CCode),call(ECode).
|
| 267 | +as_p1_exec(rtrace(T),TRet) :- !, rtrace(as_p1_exec(T,TRet)). |
| 268 | +as_p1_exec(call(P1,T),TRet) :- !, call(P1,as_p1_exec(T,TRet)). |
| 269 | +%as_p1_exec(X,Y) :- as_p1_expr(X,S),eval(S,Y). |
267 | 270 | as_p1_exec(X,X) :- !.
|
268 | 271 |
|
269 | 272 | as_p1_expr(X,X) :- \+ compound(X), !.
|
|
272 | 275 | as_p1_expr(ispeEn(_,_,NRet),NRet).
|
273 | 276 | as_p1_expr(ispeEnN(_,_,NRet,NCode),NRet) :- !, call(NCode).
|
274 | 277 | as_p1_expr(ispeEnNC(_,_,NRet,NCode,CCode),NRet) :- !,call(CCode),call(NCode).
|
| 278 | +as_p1_expr(rtrace(T),TRet) :- !, rtrace(as_p1_expr(T,TRet)). |
| 279 | +as_p1_expr(call(P1,T),TRet) :- !, call(P1,as_p1_expr(T,TRet)). |
275 | 280 | as_p1_expr(X,X) :- !.
|
276 | 281 |
|
277 | 282 | create_p1(URet,[],[ispu,URet]) :- !.
|
|
516 | 521 | subst001(X,E,_,XX),unnumbervars_wco(XX,XXX).
|
517 | 522 | unnumbervars_wco(X,X).
|
518 | 523 |
|
519 |
| -% max_integer_in_term(+Term, -Max) |
520 |
| -max_integer_in_term(Term, Start, Max) :- |
| 524 | +% max_var_integer_in_term(+Term, -Max) |
| 525 | +max_var_integer_in_term(Term, Start, Max) :- |
521 | 526 | Box = box(Start), % Correct initialization
|
522 |
| - forall( ( sub_term_safely(Int, Term), integer(Int), ( box(Int) @> Box )), |
| 527 | + forall( ( sub_term_safely(CmpdVar, Term), compound(CmpdVar), CmpdVar = '$VAR'(Int), integer(Int), ( box(Int) @> Box )), |
523 | 528 | nb_setarg(1, Box, Int)),
|
524 | 529 | arg(1, Box, Max),!.
|
525 | 530 |
|
526 | 531 | number_vars_wo_conficts(X,XX):-
|
527 | 532 | copy_term(X,XX),
|
528 |
| - woct(max_integer_in_term(XX,0,N)), |
| 533 | + woct(max_var_integer_in_term(XX,0,N)), |
529 | 534 | succ(N,N2),
|
530 | 535 | numbervars(XX,N2,_,[attvar(skip)]).
|
531 | 536 |
|
|
1990 | 1995 | create_prefixed_name('mc_',LenArgs,Fn,FnWPrefix),
|
1991 | 1996 | sum_list(LenArgs,LenArgsTotal),
|
1992 | 1997 | LenArgsTotalPlus1 is LenArgsTotal+1,
|
1993 |
| - functor(Info,FnWPrefix,LenArgsTotalPlus1), |
| 1998 | + functor_chkd(Info,FnWPrefix,LenArgsTotalPlus1), |
1994 | 1999 | skip_redef_head(user,Info),!.
|
1995 | 2000 |
|
1996 | 2001 | into_fa(Fn/[Arity],Fn,Arity):- must_be(number,Arity).
|
|
2034 | 2039 | label_arg_types(F,N2,Args).
|
2035 | 2040 |
|
2036 | 2041 | % label_arg_n_type(F,0,A):- !, label_type_assignment(A,F).
|
2037 |
| -label_arg_n_type(F,N,A):- compound(F),functor(F,Fn,Add),Is is Add+N, !, label_arg_n_type(Fn,Is,A). |
| 2042 | +label_arg_n_type(F,N,A):- compound(F),functor_chkd(F,Fn,Add),Is is Add+N, !, label_arg_n_type(Fn,Is,A). |
2038 | 2043 | label_arg_n_type(F,N,A):- add_type_to(A,arg(F,N)),!.
|
2039 | 2044 |
|
2040 | 2045 | add_type_to(V,T):- is_list(T), !, maplist(add_type_to(V),T).
|
|
2361 | 2366 | in_type_set(Set,Type):- Set==Type,!.
|
2362 | 2367 | in_type_set(Set,Type):- compound(Set),arg(_,Set,Arg),in_type_set(Arg,Type).
|
2363 | 2368 |
|
2364 |
| -b_put_set(Set,Type):- functor(Set,_,Arg),!,b_put_nset(Set,Arg,Type). |
| 2369 | +b_put_set(Set,Type):- functor_chkd(Set,_,Arg),!,b_put_nset(Set,Arg,Type). |
2365 | 2370 | b_put_nset(Set,_,Type):- in_type_set(Set,Type),!.
|
2366 | 2371 | b_put_nset(Set,N,Type):- arg(N,Set,Arg),
|
2367 | 2372 | (compound(Arg)->b_put_set(Arg,Type);b_setarg(N,Set,[Type|Arg])).
|
|
2428 | 2433 | append_sets(RefsL,Refs):- flatten(RefsL,Flat),list_to_set(Flat,Refs).
|
2429 | 2434 | compiled_info_s(S,Refs):-
|
2430 | 2435 | findall(Ref,(compiler_data(F/A),compiled_refs(S,F,A,Ref)),RefsL),append_sets(RefsL,Refs1),
|
2431 |
| - findall(Ref,(current_predicate(S/A),functor(P,S,A),clause(P,_,Ref)),Refs2),append_sets([Refs1,Refs2],Refs). |
| 2436 | + findall(Ref,(current_predicate(S/A),functor_chkd(P,S,A),clause(P,_,Ref)),Refs2),append_sets([Refs1,Refs2],Refs). |
2432 | 2437 | compiled_info_f(F,Refs):- compiled_info_s(F,Refs1), compiled_info_p(F,Refs2),append_sets([Refs1,Refs2],Refs).
|
2433 | 2438 | compiled_info_p(F,Refs):-
|
2434 |
| - findall(Ref,(current_predicate(F/A),functor(P,F,A),current_module(M), |
| 2439 | + findall(Ref,(current_predicate(F/A),functor_chkd(P,F,A),current_module(M), |
2435 | 2440 | \+ \+ predicate_property(M:P,_), \+ predicate_property(M:P,imported_from(_)),
|
2436 | 2441 | clause(M:P,_,Ref)),Refs).
|
2437 | 2442 |
|
2438 | 2443 | compiled_refs(Symbol,F,A,Info):-
|
2439 |
| - functor(P,F,A),clause(P,B,Ref), (\+ compiler_data_no_call(F/A) -> call(B)), symbol_in(2,Symbol,P), |
| 2444 | + functor_chkd(P,F,A),clause(P,B,Ref), (\+ compiler_data_no_call(F/A) -> call(B)), symbol_in(2,Symbol,P), |
2440 | 2445 | (B==true->Info=Ref;Info=P).
|
2441 | 2446 |
|
2442 | 2447 |
|
|
2478 | 2483 | transpile_call_prefix(Fn,Arity,CFn),
|
2479 | 2484 |
|
2480 | 2485 | ((current_predicate(CFn/Arity) -> true ;
|
2481 |
| - must_det_lls((( functor(CallP,CFn,Arity), |
| 2486 | + must_det_lls((( functor_chkd(CallP,CFn,Arity), |
2482 | 2487 | CallP @.. [CFn|Args],
|
2483 | 2488 | transpile_impl_prefix(Fn,Arity,IFn),
|
2484 | 2489 | CallI @.. [IFn|Args],
|
|
2504 | 2509 | prefix_impl_preds('mc__1_',F,A):- is_transpile_call_prefix(F,A,Fn),current_predicate(Fn/A), \+ prefix_impl_preds_pp(_,F,A).
|
2505 | 2510 | prefix_impl_preds('mi__1_',F,A):- is_transpile_impl_prefix(F,A,Fn),current_predicate(Fn/A), \+ prefix_impl_preds_pp(_,F,A).
|
2506 | 2511 |
|
2507 |
| -prefix_impl_preds_pp(Prefix,F,A):- predicate_property('mc__1_2_:'(_,_,_),file(File)),predicate_property(Preds,file(File)),functor(Preds,Fn,A), |
| 2512 | +prefix_impl_preds_pp(Prefix,F,A):- predicate_property('mc__1_2_:'(_,_,_),file(File)),predicate_property(Preds,file(File)),functor_chkd(Preds,Fn,A), |
2508 | 2513 | ((transpile_impl_prefix(Prefix);transpile_call_prefix(Prefix)),atom_list_concat([Prefix,_FNArity,'_',F],Fn)).
|
2509 | 2514 |
|
2510 | 2515 | maplist_and_conj(_,A,B):- fullvar(A),!,B=A.
|
|
2543 | 2548 | extract_caller(H:-_,CallerInt,CallerSz):- !, extract_caller(H,CallerInt,CallerSz).
|
2544 | 2549 | extract_caller([=,H,_],CallerInt,CallerSz):- !, extract_caller(H,CallerInt,CallerSz).
|
2545 | 2550 | extract_caller(P,F,A):- \+ callable(P),!, F=P,A=0.
|
2546 |
| -extract_caller(P,F,A):- \+ is_list(P), functor(P,F,A). |
| 2551 | +extract_caller(P,F,A):- \+ is_list(P), functor_chkd(P,F,A). |
2547 | 2552 |
|
2548 | 2553 |
|
2549 | 2554 | maybe_lazy_list(_,_,_,[],[]):-!.
|
|
2908 | 2913 | transpile_call_prefix(Fn,CFn),
|
2909 | 2914 | %trace,
|
2910 | 2915 | ((current_predicate(CFn/Arity) -> true ;
|
2911 |
| - must_det_lls((( functor(CallP,CFn,Arity), |
| 2916 | + must_det_lls((( functor_chkd(CallP,CFn,Arity), |
2912 | 2917 | CallP @.. [CFn|Args],
|
2913 | 2918 | transpile_impl_prefix(Fn,IFn),
|
2914 | 2919 | CallI @.. [IFn|Args],
|
|
2922 | 2927 | prefix_impl_preds('mc__',F,A):- is_transpile_call_prefix(F,Fn),current_predicate(Fn/A), \+ prefix_impl_preds_pp(_,F,A).
|
2923 | 2928 | prefix_impl_preds('mi__',F,A):- is_transpile_impl_prefix(F,Fn),current_predicate(Fn/A), \+ prefix_impl_preds_pp(_,F,A).
|
2924 | 2929 |
|
2925 |
| -prefix_impl_preds_pp(Prefix,F,A):- predicate_property('mc__:'(_,_,_),file(File)),predicate_property(Preds,file(File)),functor(Preds,Fn,A), |
| 2930 | +prefix_impl_preds_pp(Prefix,F,A):- predicate_property('mc__:'(_,_,_),file(File)),predicate_property(Preds,file(File)),functor_chkd(Preds,Fn,A), |
2926 | 2931 | ((transpile_impl_prefix(Prefix);transpile_call_prefix(Prefix)),atom_concat(Prefix,F,Fn)).
|
2927 | 2932 |
|
2928 | 2933 | maplist_and_conj(_,A,B):- fullvar(A),!,B=A.
|
|
2961 | 2966 | extract_caller(H:-_,CallerInt,CallerSz):- !, extract_caller(H,CallerInt,CallerSz).
|
2962 | 2967 | extract_caller([=,H,_],CallerInt,CallerSz):- !, extract_caller(H,CallerInt,CallerSz).
|
2963 | 2968 | extract_caller(P,F,A):- \+ callable(P),!, F=P,A=0.
|
2964 |
| -extract_caller(P,F,A):- \+ is_list(P), functor(P,F,A). |
| 2969 | +extract_caller(P,F,A):- \+ is_list(P), functor_chkd(P,F,A). |
2965 | 2970 |
|
2966 | 2971 |
|
2967 | 2972 | maybe_lazy_list(_,_,_,[],[]):-!.
|
|
3017 | 3022 | catch(quietly(as_tf(apply(F,List),R)),error(existence_error(procedure,F/_),_),
|
3018 | 3023 | quietly(catch(eval_args([F|List],R),_, R=[F|List])))).
|
3019 | 3024 |
|
3020 |
| -%u_assign([V|VI],[V|VO]):- nonvar(V),is_metta_data_functor(_Eq,V),!,maplist(eval_args,VI,VO). |
| 3025 | +%u_assign([V|VI],[V|VO]):- nonvar(V),is_metta_data_functor_chkd(_Eq,V),!,maplist(eval_args,VI,VO). |
3021 | 3026 |
|
3022 | 3027 | u_assign_c((F:-List),R):- !, R = (F:-List).
|
3023 | 3028 |
|
3024 | 3029 | /*
|
3025 | 3030 | u_assign_c(Cmp,RR):-
|
3026 |
| - functor(Cmp,F,_), |
| 3031 | + functor_chkd(Cmp,F,_), |
3027 | 3032 | current_predicate(F,_),
|
3028 | 3033 | debug(todo,'u_assign_c INTERP: ~q',[Cmp]),!,
|
3029 | 3034 | call(Cmp,RR).*/
|
3030 | 3035 | u_assign_c(FList,RR):-
|
3031 |
| - functor(FList,F,_), % (F == 'car-atom' -> trace ; true), |
| 3036 | + functor_chkd(FList,F,_), % (F == 'car-atom' -> trace ; true), |
3032 | 3037 | (catch(quietlY(call(FList,R)),error(existence_error(procedure,F/_),_),
|
3033 | 3038 | catch(quietlY(as_tf(FList,R)),error(existence_error(procedure,F/_),_),
|
3034 | 3039 | ((p2m(FList,[F0|List0]),catch(eval_args([F0|List0],R),_, R=~[F0|List0])))))),!,
|
|
3397 | 3402 | compile_flow_control2(HeadIs, LazyVars, RetResult, ResultLazy, Convert, Converted).
|
3398 | 3403 |
|
3399 | 3404 | compile_flow_control2(HeadIs, LazyVars, _Result, ResultLazy, Convert, Converted) :- fail,
|
3400 |
| - functor(Convert,Func,PA), |
| 3405 | + functor_chkd(Convert,Func,PA), |
3401 | 3406 | functional_predicate_arg(Func,PA,Nth),
|
3402 | 3407 | Convert =~ [Func|PredArgs],
|
3403 | 3408 | nth1(Nth,PredArgs,Result,FuncArgs),
|
|
3430 | 3435 | strip_m(HH,HHH),HHH=@=H2,
|
3431 | 3436 | strip_m(BB,BBB),BBB=@=B,!.
|
3432 | 3437 |
|
3433 |
| -%get_clause_pred(UAC,F,A):- expand_to_hb(UAC,H,_),strip_m(H,HH),functor(HH,F,A). |
| 3438 | +%get_clause_pred(UAC,F,A):- expand_to_hb(UAC,H,_),strip_m(H,HH),functor_chkd(HH,F,A). |
3434 | 3439 |
|
3435 | 3440 |
|
3436 | 3441 | % :- dynamic(needs_tabled/2).
|
|
3753 | 3758 | pi(PI):- PI is pi.
|
3754 | 3759 |
|
3755 | 3760 | % Retrieve Head of the List
|
3756 |
| -'car-atom'(List, Head):- eval_H(['car-atom', List], Head). |
| 3761 | +% 'car-atom'(List, Head):- eval_H(['car-atom', List], Head). |
3757 | 3762 |
|
3758 | 3763 |
|
3759 | 3764 | % Mapping any current predicate F/A to a function, if it's not tricky
|
|
3767 | 3772 | predicate_arity(F,A):- current_predicate(F/A).
|
3768 | 3773 | % Certain constructs should not be converted to functions.
|
3769 | 3774 | not_function(P):- atom(P),!,not_function(P,0).
|
3770 |
| -not_function(P):- callable(P),!,functor(P,F,A),not_function(F,A). |
| 3775 | +not_function(P):- callable(P),!,functor_chkd(P,F,A),not_function(F,A). |
3771 | 3776 | not_function(F,A):- is_arity_0(F,FF),!,not_function(FF,A).
|
3772 | 3777 | not_function(!,0).
|
3773 | 3778 | not_function(print,1).
|
|
3784 | 3789 | not_function('True',0).
|
3785 | 3790 | not_function(F,A):- predicate_arity(F,A),AA is A+1, \+ decl_functional_predicate_arg(F,AA,_).
|
3786 | 3791 |
|
3787 |
| -needs_call_fr(P):- is_function(P,_Nth),functor(P,F,A),AA is A+1, \+ current_predicate(F/AA). |
| 3792 | +needs_call_fr(P):- is_function(P,_Nth),functor_chkd(P,F,A),AA is A+1, \+ current_predicate(F/AA). |
3788 | 3793 |
|
3789 | 3794 | is_control_structure(F,A):- atom(F), atom_concat('if-',_,F),A>2.
|
3790 | 3795 |
|
|
3803 | 3808 | is_function(AsFunction, Nth) :- is_arity_0(AsFunction,_), !,Nth=1.
|
3804 | 3809 | is_function(AsFunction, Nth) :-
|
3805 | 3810 | callable(AsFunction),
|
3806 |
| - functor(AsFunction, Functor, A), |
| 3811 | + functor_chkd(AsFunction, Functor, A), |
3807 | 3812 | \+ not_function(Functor, A),
|
3808 | 3813 | AA is A + 1,
|
3809 | 3814 | functional_predicate_arg_maybe(Functor, AA, Nth).
|
|
4139 | 4144 | nonvar(AsFunction),
|
4140 | 4145 | compound(AsFunction),
|
4141 | 4146 | \+ is_arity_0(AsFunction,_),
|
4142 |
| - functor(AsFunction,F,A), |
| 4147 | + functor_chkd(AsFunction,F,A), |
4143 | 4148 | HeadIs\=@=AsFunction,
|
4144 |
| - \+ (compound(HeadIs), (is_arity_0(HeadIs,HF);functor(HeadIs,HF,_))-> HF==F), |
| 4149 | + \+ (compound(HeadIs), (is_arity_0(HeadIs,HF);functor_chkd(HeadIs,HF,_))-> HF==F), |
4145 | 4150 | (into_x_assign(AsFunction, Result,AsPred)
|
4146 | 4151 | -> true
|
4147 | 4152 | ; (AA is A+1,
|
|
4284 | 4289 | % Converts a given predicate AsPred to its equivalent function term AsFunction
|
4285 | 4290 | pred_to_funct(AsPred, AsFunction, Result) :-
|
4286 | 4291 | compound(AsPred), % Checks if AsPred is a compound term
|
4287 |
| - functor(AsPred, F, A), % Retrieves the functor F and arity A of AsPred |
| 4292 | + functor_chkd(AsPred, F, A), % Retrieves the functor F and arity A of AsPred |
4288 | 4293 | functional_predicate_arg(F, A, Nth),!, % Finds the Nth argument where the result should be
|
4289 | 4294 | arg(Nth, AsPred, Result), % Retrieves the result from the Nth argument of AsPred
|
4290 | 4295 | remove_funct_arg(AsPred, Nth, AsFunction). % Constructs the function AsFunction by removing the Nth argument from AsPred
|
4291 | 4296 |
|
4292 | 4297 | % If not found in functional_predicate_arg/3, it tries to construct AsFunction by removing the last argument from AsPred
|
4293 | 4298 | pred_to_funct(AsPred, AsFunction, Result) :-
|
4294 | 4299 | compound(AsPred), !,
|
4295 |
| - functor(AsPred, _, Nth), |
| 4300 | + functor_chkd(AsPred, _, Nth), |
4296 | 4301 | arg(Nth, AsPred, Result),
|
4297 | 4302 | remove_funct_arg(AsPred, Nth, AsFunction).
|
4298 | 4303 |
|
|
4314 | 4319 | findall(Head, member((Head:-_), HeadBodiesList), Heads),
|
4315 | 4320 | % Find the least general head among the collected Heads
|
4316 | 4321 | least_general_head(Heads, LeastHead),
|
4317 |
| - functor(LeastHead,F,A),functor(NewHead,F,A), |
| 4322 | + functor_chkd(LeastHead,F,A),functor_chkd(NewHead,F,A), |
4318 | 4323 | % Transform and combine bodies according to the new head found
|
4319 | 4324 | transform_and_combine_bodies(HeadBodiesList, NewHead, NewCombinedBodies)),
|
4320 | 4325 | \+ \+ (
|
|
4339 | 4344 | % This predicate is conceptual and will require more complex processing depending on the actual structures of the heads.
|
4340 | 4345 | generalization(Head1, Head2, GeneralizedHead) :-
|
4341 | 4346 | % Ensure the functor names and arities are the same between Head1 and Head2.
|
4342 |
| - functor(Head1, Name, Arity), |
4343 |
| - functor(Head2, Name, Arity), |
4344 |
| - functor(GeneralizedHead, Name, Arity), |
| 4347 | + functor_chkd(Head1, Name, Arity), |
| 4348 | + functor_chkd(Head2, Name, Arity), |
| 4349 | + functor_chkd(GeneralizedHead, Name, Arity), |
4345 | 4350 | % Generalize the arguments of the heads.
|
4346 | 4351 | generalize_args(Arity, Head1, Head2, GeneralizedHead).
|
4347 | 4352 |
|
|
0 commit comments