|
265 | 265 | evals_to(XX,Y):- Y=@=XX,!. |
266 | 266 | evals_to(XX,Y):- Y=='True',!, is_True(XX),!. |
267 | 267 |
|
268 | | -:- set_prolog_flag(optimise, false). |
269 | | -:- set_prolog_flag(access_level, system). |
| 268 | +%:- set_prolog_flag(optimise, false). |
| 269 | +%:- set_prolog_flag(access_level, system). |
270 | 270 | check_term_depth(X,Y):- find_term_cycles(X), X=Y. |
271 | 271 | check_term_depth(X,Y):- find_term_cycles(Y), X=Y. |
272 | 272 | find_term_cycles(X):- find_term_cycles(100,X). |
273 | 273 | find_term_cycles(_,X):- \+ acyclic_term_nat(X), notrace, nl,nl, writeq(X), nl,nl, break. |
274 | 274 | find_term_cycles(N,X):- term_depth(X,Deep), Deep>N, notrace, nl,nl, writeq(X), nl,nl, break. |
275 | 275 |
|
276 | | -%eval_args(_Eq,_RetType,_Dpth,_Self,X,Y):- check_term_depth(X,Y),!. |
277 | | -eval_args(_Eq,_RetType,_Dpth,_Slf,X,Y):- var(X),nonvar(Y),!,X=Y. |
278 | | -eval_args(_Eq,_RetType,_Dpth,_Slf,X,Y):- notrace(self_eval(X)),!,Y=X. |
| 276 | +eval_args(_Eq,_RetType,_Dpth,_Slf,X,Y):- var(X),nonvar(Y),!, |
| 277 | + unify_woc(X,Y). |
| 278 | +eval_args(_Eq,_RetType,_Dpth,_Slf,X,Y):- notrace(self_eval(X)),!, |
| 279 | + unify_woc(X,Y). |
279 | 280 |
|
280 | 281 | eval_args(Eq,RetType,Depth,Self,X,Y):- |
281 | 282 | notrace(nonvar(Y)), var(RetType), |
|
380 | 381 | % % uncommented causes 7% failure but a 10x speedup |
381 | 382 | % subst_args_here(Eq,RetType,Depth2,Self,Y,YO):- Y=YO. |
382 | 383 | % % this next one at least causes no failures and 5x speedup |
383 | | -subst_args_here(_Eq,_RetType,_Depth2,_Self,Y,YO):- iz_conz(Y), \+ is_list(Y), !, bt,trace, break, Y=YO. |
| 384 | +subst_args_here(_Eq,_RetType,_Depth2,_Self,Y,YO):- iz_conz(Y), \+ is_list(Y), !, maybe_bt(depth), break, Y=YO. |
384 | 385 | %subst_args_here(Eq,RetType,Depth2,Self,Y,YO):- !, Y=YO. |
385 | 386 | subst_args_here(Eq,RetType,Depth2,Self,Y,YO):- !, |
386 | 387 | subst_once(subst_args(Eq,RetType,Depth2,Self,Y,YO)*->true;Y=YO). |
|
486 | 487 | with_debug(Type,eval_09(Eq,RetType,Depth,Self,X,Y)). |
487 | 488 | eval_08(Eq,RetType,Depth,Self,X,Y):- eval_09(Eq,RetType,Depth,Self,X,Y). |
488 | 489 |
|
489 | | -%eval_09(_Eq,_RetType, Depth,_Slf,X,Y):- Depth< 0, !, X=Y, fail. |
490 | | -%eval_09(_Eq,_RetType, Depth,_Slf,X,Y):- Depth< 1, !, X=Y. |
491 | | -%eval_09(_Eq,_RetType, Depth,_Slf,_X,_Y):- Depth<1, if_trace(e,bt),!, fail. |
| 490 | +%eval_09(_Eq,_RetType, Depth,_Slf,X,Y):- Depth< 0, !, unify_woc(X,Y), fail. |
| 491 | +%eval_09(_Eq,_RetType, Depth,_Slf,X,Y):- Depth< 1, !, unify_woc(X,Y). |
| 492 | +%eval_09(_Eq,_RetType, Depth,_Slf,_X,_Y):- Depth<1, if_trace(e,maybe_bt),!, fail. |
492 | 493 |
|
493 | 494 | %hybrid_interp :- !. |
494 | 495 | hybrid_interp :- option_value(compile,hybrid),!. |
|
518 | 519 | ((copy_term(X+Y,YC), YC = YY) |
519 | 520 | -> nop(debug(metta(todo),'no_repeat in ~w: ~q',[ThisNth,X->Y])) |
520 | 521 | ; once((dmsg('repeats in'([ThisNth,X->Y])), |
521 | | - %bt, |
| 522 | + %maybe_bt, |
522 | 523 | dumpST, |
523 | 524 | dmsg('repeats in'([ThisNth,X->Y])), |
524 | 525 | !,fail))). |
|
579 | 580 |
|
580 | 581 | sanity_check_eval(_,_):- is_testing,!. |
581 | 582 | sanity_check_eval(_,_):- !. |
582 | | -sanity_check_eval(Which,X):- tracing,notrace,!,call_cleanup(\+ insanity_check_eval(Which,X), maybe_trace(unknown)),!. |
| 583 | +sanity_check_eval(Which,X):- tracing,notrace,!,call_cleanup(\+ insanity_check_eval(Which,X), maybe_trace(Which)),!. |
583 | 584 | sanity_check_eval(Which,X):- \+ insanity_check_eval(Which,X), !. |
584 | 585 |
|
585 | | -%eval_10(Eq,RetType,Depth,Self,X,Y):- \+ sanity_check_eval(eval_10_in,X),X=Y,!,var_pass(Eq,RetType,Depth,Self,Y). |
| 586 | +%eval_10(Eq,RetType,Depth,Self,X,Y):- \+ sanity_check_eval(eval_10_in,X),unify_woc(X,Y),!,var_pass(Eq,RetType,Depth,Self,Y). |
586 | 587 |
|
587 | 588 | % The first eval_20/6 clause |
588 | 589 | eval_20(Eq,RetType,Depth,Self,X,Y):- var(X), !, % sanity_check_eval(eval_20_var,X), |
589 | | - Y=X,!,var_pass(Eq,RetType,Depth,Self,Y). |
| 590 | + unify_woc(X,Y),!,var_pass(Eq,RetType,Depth,Self,Y). |
590 | 591 |
|
591 | | -%eval_20(Eq,RetType,Depth,Self,X,Y):- \+ sanity_check_eval(eval_20_in,X),X=Y,!,var_pass(Eq,RetType,Depth,Self,Y). |
| 592 | +%eval_20(Eq,RetType,Depth,Self,X,Y):- \+ sanity_check_eval(eval_20_in,X),unify_woc(X,Y),!,var_pass(Eq,RetType,Depth,Self,Y). |
592 | 593 |
|
593 | 594 | eval_10(Eq,RetType,Depth,Self,X,Y):- \+ compound(X), !, |
594 | 595 | as_prolog_x(Depth,Self,X,XX), |
|
618 | 619 |
|
619 | 620 |
|
620 | 621 | leave_args_alone('->'). |
621 | | -%eval_10_disabled(_Eq,_RetType,_Depth,_Self,[Fn|Args],Y):- leave_args_alone(Fn), !, Y=[Fn|Args]. |
| 622 | +eval_10_disabled(_Eq,_RetType,_Depth,_Self,[Fn|Args],Y):- leave_args_alone(Fn), !, Y=[Fn|Args]. |
622 | 623 |
|
623 | 624 | eval_10(Eq,RetType,Depth,Self,['eval-in-only',Where,Eval],Y):- |
624 | 625 | Where==interp,!, |
|
883 | 884 | %fbug(expand_eval(X,XX)), |
884 | 885 | eval_10(Eq,RetType,Depth,Self,XX,RetVal). |
885 | 886 |
|
886 | | -expand_eval(X,Y):- \+ is_list(X),!, X=Y. |
| 887 | +expand_eval(X,Y):- \+ is_list(X),!, unify_woc(X,Y). |
887 | 888 | expand_eval([H|A],[H|AA]):- \+ ground(H),!,maplist(expand_eval,A,AA). |
888 | 889 | expand_eval(['let*',Lets,Body],NewBody):- expand_let_star(Lets,Body,NewBody),!. |
889 | 890 | expand_eval([H|A],[H|AA]):- maplist(expand_eval,A,AA). |
|
1364 | 1365 | equal_enough_for_test_renumbered_l(not_alpha_equ,XX,YY), RetVal). |
1365 | 1366 |
|
1366 | 1367 | loonit_assert_source_tf_empty(Src,XX,YY,Goal,Check,RetVal):- |
1367 | | - %ignore(nortrace), |
1368 | 1368 | loonit_assert_source_tf(Src,Goal,Check,TF), |
1369 | | - %ignore(rtrace), |
1370 | 1369 | tf_to_empty(TF,['Error',Src,['\nGot: ',XX,'\nEXP: ',YY]],RetVal). |
1371 | 1370 |
|
1372 | 1371 | tf_to_empty(TF,Else,RetVal):- |
|
1658 | 1657 | as_tf('=alpha'(X,Y),TF). |
1659 | 1658 |
|
1660 | 1659 | equal_renumbered(X0,Y0,XX,YY):- |
1661 | | - max_var_number(X+Y,0,N),succ(N,N2), |
| 1660 | + max_var_number(X0+Y0,0,N),succ(N,N2), |
1662 | 1661 | copy_term(X0+Y0,X+Y), |
1663 | 1662 | term_variables(X,VXs), term_variables(Y,VYs), |
1664 | | - merge_same_named_vars(VXs,VYs,Same,Merges,_LOXVs,_LOYVs), |
1665 | | - max_var_number(X+Y,0,N),succ(N,N2), |
| 1663 | + merge_same_named_vars(VXs,VYs,Same,Merges,LOXVs,LOYVs), |
| 1664 | + debug_info(varnames,merge_same_named_vars(VXs,VYs,Same,Merges,LOXVs,LOYVs)), |
1666 | 1665 | maplist(remerge_attrs,Merges), |
1667 | 1666 | maplist(remove_attr(vn),VXs), maplist(remove_attr(vn),VYs), |
1668 | 1667 | numbervars(Same,N2,_,[attvar(skip)]), |
1669 | 1668 | %numbervars(_Merges,N3,_,[attvar(skip)]), |
1670 | 1669 | renumber_vars_wo_confict_tu(X,XX), |
1671 | 1670 | renumber_vars_wo_confict_tu(Y,YY),!. |
1672 | | - %if_tracemsg(unknown,equal_enough_for_test(P2,XX,YY)), |
| 1671 | + %debug_info(unknown,equal_enough_for_test(P2,XX,YY)), |
1673 | 1672 |
|
1674 | 1673 |
|
1675 | 1674 | renumber_vars_wo_confict_tu(X,XXX):- |
|
1895 | 1894 |
|
1896 | 1895 | eval_10(Eq,RetType,Depth,Self,['switch',A,CL|T],Res):- !, |
1897 | 1896 | eval_10(Eq,RetType,Depth,Self,['case',A,CL|T],Res). |
| 1897 | +eval_10_new(Eq,RetType,Depth,Self,I,Res):- fail, |
| 1898 | + once(metta_to_metta_body_macro_recurse(eval10,I,O)),I\=@=O,!, |
| 1899 | + eval_10p(Eq,RetType,Depth,Self,O,Res). |
1898 | 1900 |
|
1899 | 1901 | eval_10_disabled(Eq,RetType,Depth,Self,[P,X|More],YY):- fail, is_list(X),X=[_,_,_],simple_math(X), |
1900 | 1902 | eval_selfless_2(X,XX),X\=@=XX,!, eval_20(Eq,RetType,Depth,Self,[P,XX|More],YY). |
|
3145 | 3147 | % - E: The resulting element that is part of the union of the two sets |
3146 | 3148 | lazy_union(P2, E1^Call1, E2^Call2, E) :- |
3147 | 3149 | % Step 1: Use lazy_findall/3 to declare that all elements satisfying Call1 are supposedly in List1 |
3148 | | - lazy_findall(E1, Call1, List1), |
| 3150 | + maybe_lazy_findall(E1, Call1, List1), |
3149 | 3151 | % Step 2: Use lazy_findall/3 to declare that all elements satisfying Call2 are supposedly in List2 |
3150 | | - lazy_findall(E2, Call2, List2), |
| 3152 | + maybe_lazy_findall(E2, Call2, List2), |
3151 | 3153 | % Step 3: Perform the union logic |
3152 | 3154 | ( % Case 1: If E is a member of List1, include it in the result |
3153 | 3155 | member(E, List1) |
|
3335 | 3337 | % Step 1: Evaluate Call1 to generate E1 |
3336 | 3338 | call(Call1), |
3337 | 3339 | % Step 2: Use lazy_findall/3 to declare that all elements satisfying Call2 are supposedly in List2 |
3338 | | - lazy_findall(E2, Call2, List2), |
| 3340 | + maybe_lazy_findall(E2, Call2, List2), |
3339 | 3341 | % Step 3: Perform the intersection logic |
3340 | 3342 | % Only return E1 if it is not a member of List2 |
3341 | 3343 | member(E2, List2), call(P2,E1,E2). |
|
3353 | 3355 | % Step 1: Evaluate Call1 to generate E1 |
3354 | 3356 | call(Call1), |
3355 | 3357 | % Step 2: Use lazy_findall/3 to declare that all elements satisfying Call2 are supposedly in List2 |
3356 | | - lazy_findall(E2, Call2, List2), |
| 3358 | + maybe_lazy_findall(E2, Call2, List2), |
3357 | 3359 | % Step 3: Perform the subtraction logic |
3358 | 3360 | % Only return E1 if it is not a member of List2 |
3359 | 3361 | \+ (member(E2, List2), call(P2, E1, E2)). |
3360 | 3362 |
|
3361 | 3363 |
|
| 3364 | +maybe_lazy_findall(T,G,L):- option_value(lazy_findall,true),!,lazy_findall(T,G,L). |
| 3365 | +maybe_lazy_findall(T,G,L):- findall(T,G,L). |
| 3366 | + |
3362 | 3367 | eval_20(Eq,RetType,Depth,Self,PredDecl,Res):- |
3363 | 3368 | Do_more_defs = do_more_defs(true), |
3364 | 3369 | clause(eval_21(Eq,RetType,Depth,Self,PredDecl,Res),Body), |
|
0 commit comments