|
61 | 61 | :- meta_predicate(fake_notrace(0)). |
62 | 62 | :- meta_predicate(color_g_mesg(+,0)). |
63 | 63 | :- multifile(color_g_mesg/2). |
| 64 | +:- discontiguous(symbol_impl_exists/3). |
| 65 | +:- discontiguous(symbol_impl_not_exists/3). |
| 66 | +:- dynamic(symbol_impl_exists/3). |
| 67 | +:- dynamic(symbol_impl_not_exists/3). |
| 68 | +:- discontiguous(symbol_impl_only/3). |
64 | 69 |
|
65 | 70 | %self_eval0(X):- var(X),!,fail. |
66 | 71 | self_eval0(X):- \+ callable(X),!. |
|
222 | 227 |
|
223 | 228 | %! eval_args(+X,-Y) is semidet. |
224 | 229 | eval_args(X,Y):- current_self(Self), |
225 | | - default_depth(DEPTH), |
| 230 | + default_start_depth(DEPTH), |
226 | 231 | eval_args(DEPTH,Self,X,Y). |
227 | 232 | %eval_args(Eq,RetType,Depth,_Self,X,_Y):- forall(between(6,Depth,_),write(' ')),writeqln(eval_args(Eq,RetType,X)),fail. |
228 | 233 | eval_args(Depth,Self,X,Y):- eval_args('=',_RetType,Depth,Self,X,Y). |
229 | 234 |
|
230 | | -:- dynamic(symbol_impl_exists/3). |
231 | | -:- dynamic(symbol_impl_not_exists/3). |
232 | | -symbol_impl_not_exists(interp,'random-int',_). |
233 | 235 | symbol_impl_not_exists(compiler,'notcompiled',_). |
234 | 236 | symbol_impl_exists(compiler,Sym,A):- symbol_impl_not_exists(interp,Sym,A). |
235 | 237 | skip_scan_impl(symbol_impl_exists/3). |
|
251 | 253 | listing(symbol_impl_exists). |
252 | 254 |
|
253 | 255 | eval_20(X,Y):- current_self(Self), |
254 | | - default_depth(DEPTH), |
| 256 | + default_start_depth(DEPTH), |
255 | 257 | eval_20(DEPTH,Self,X,Y). |
256 | 258 | %eval_20(Eq,RetType,Depth,_Self,X,_Y):- forall(between(6,Depth,_),write(' ')),writeqln(eval_20(Eq,RetType,X)),fail. |
257 | 259 | eval_20(Depth,Self,X,Y):- eval_20('=',_RetType,Depth,Self,X,Y). |
258 | 260 |
|
| 261 | +default_start_depth(0). |
259 | 262 |
|
260 | 263 | eval_40(X,Y):- current_self(Self), |
261 | | - default_depth(DEPTH), |
| 264 | + default_start_depth(DEPTH), |
262 | 265 | eval_40(DEPTH,Self,X,Y). |
263 | 266 | %eval_40(Eq,RetType,Depth,_Self,X,_Y):- forall(between(6,Depth,_),write(' ')),writeqln(eval_40(Eq,RetType,X)),fail. |
264 | 267 | eval_40(Depth,Self,X,Y):- eval_40('=',_RetType,Depth,Self,X,Y). |
|
475 | 478 |
|
476 | 479 |
|
477 | 480 | eval_09(Eq,RetType,Depth,Self,X,Y):- |
478 | | - nb_current('eval_in_only', interp), !, |
| 481 | + nb_current('eval_in_only', interp), !, |
479 | 482 | woc(eval_10(Eq,RetType,Depth,Self,X,Y)). |
480 | | -eval_09(Eq,RetType,Depth,Self,X,Y):- |
481 | | - nb_current('eval_in_only', compiler), !, |
482 | | - with_scope(Eq, RetType, Depth, Self, transpile_eval(X,Y)). |
483 | | -eval_09(Eq,RetType,Depth,Self,X,Y):- |
484 | | - nb_current('eval_in_only', rust), !, |
485 | | - with_scope(Eq, RetType, Depth, Self, rust_metta_run(exec(X),Y)). |
486 | | - |
487 | 483 | eval_09(Eq,RetType,Depth,Self,X,Y):- hybrid_interp, !, |
488 | 484 | eval_use_right_thing(Eq,RetType,Depth,Self,X,Y). |
489 | 485 | eval_09(Eq,RetType,Depth,Self,X,Y):- woc(eval_10(Eq,RetType,Depth,Self,X,Y)). |
|
528 | 524 | eval_10(_Eq,_RetType,_Dpth,_Self,X,YO):- self_eval(X),!,YO=X. |
529 | 525 | eval_10(_Eq,_RetType,_Dpth,_Self,X,_YO):- X==[empty],!,fail. |
530 | 526 | eval_10(_Eq,_RetType,_Dpth,_Self,X,_YO):- X==['Empty'],!,fail. |
531 | | -eval_10(_Eq,_RetType,Depth,_Self,X,YO):- overflow_depth(Depth),bt,trace,!,X=YO. |
| 527 | +eval_10(_Eq,_RetType,Depth,_Self,X,YO):- Depth<0,bt,trace,!,X=YO. |
532 | 528 | eval_10(Eq,RetType,Depth,Self,X,Y):- var(X), !, % sanity_check_eval(eval_10_var,X), |
533 | 529 | eval_20(Eq,RetType,Depth,Self,X,Y). |
534 | 530 |
|
|
560 | 556 | maplist(as_prolog_x(Depth,Self), [Sym|Args] , [ASym|Adjusted]), |
561 | 557 | eval_20(Eq,RetType,Depth,Self, [ASym|Adjusted], Y),sanity_check_eval(eval_20_not_atom,Y). |
562 | 558 |
|
563 | | -eval_10(Eq,RetType,Depth,Self,['eval-in-only',Where,Eval],Y):- |
564 | | - Where==interp,!, |
565 | | - eval_in_only(Where,eval_10(Eq,RetType,Depth,Self,Eval,Y)). |
566 | | -eval_10(Eq,RetType,Depth,Self,['eval-in-only',Where,Eval],Y):- !, |
567 | | - eval_in_only(Where,eval_args(Eq,RetType,Depth,Self,Eval,Y)). |
568 | | - |
569 | | - |
570 | | -eval_20(_Eq,_RetType,Depth,_Self,X,YO):- overflow_depth(Depth),bt,trace,!,X=YO. |
| 559 | +eval_20(_Eq,_RetType,Depth,_Self,X,YO):- Depth<0,bt,trace,!,X=YO. |
571 | 560 | eval_20(Eq,RetType,_Dpth,_Slf,Name,Y):- |
572 | 561 | atom(Name), !, |
573 | 562 | (Name=='NotReducible'->throw(metta_NotReducible); |
|
576 | 565 | sanity_check_eval(eval_20_atom,Y). |
577 | 566 |
|
578 | 567 | eval_20(_Eq,RetType,Depth,Self,[Sym|Args],Res):- |
579 | | - atomic(Sym), py_is_callable(Sym), is_list(Args), !, |
580 | | - maplist(as_prolog_x(Depth,Self), Args , Adjusted),!, |
581 | | - py_call_method_and_args_sig(RetType,[],Sym,Adjusted,Res). |
582 | | - |
583 | | -eval_20(_Eq,RetType,Depth,Self,['py-atom-call!',Sym|Args],Res):- is_list(Args), !, |
| 568 | + atomic(Sym), py_is_function(Sym), is_list(Args), !, |
584 | 569 | maplist(as_prolog_x(Depth,Self), Args , Adjusted),!, |
585 | | - py_call_method_and_args_sig(RetType,[],Sym,Adjusted,Res). |
586 | | -eval_40(Eq,RetType,Depth,Self,['py-atom-call',Sym|Args],Res):- |
587 | | - eval_20(Eq,RetType,Depth,Self,['py-atom-call!',Sym|Args],Res). |
588 | | - |
| 570 | + py_call_method_and_args(Sym,Adjusted,Ret), |
| 571 | + py_metta_return_value(RetType, Ret,Res). |
589 | 572 |
|
590 | | -eval_py_atom(_Eq,_RetType,_Depth,_Self,['py-atom',Arg|Specialize],ResO):- |
591 | | - must_det_lls((py_atom(Arg,Res))), |
592 | | - specialize_res(Res,Specialize,ResO). |
593 | 573 |
|
594 | | -eval_py_atom(_Eq,_RetType,_Depth,_Self,['py-dot',Arg1,Arg2|Specialize],ResO):- |
595 | | - must_det_lls(make_py_dot(Arg1,Arg2,Res)), |
596 | | - specialize_res(Res,Specialize,ResO). |
| 574 | +eval_py_atom(_Eq,_RetType,_Depth,_Self,['py-atom',Arg],Res):- |
| 575 | + must_det_ll((py_atom(Arg,Res))). |
597 | 576 |
|
598 | | -specialize_res(Res,Specialize,Res):- |
599 | | - if_t(Specialize\==[], debug_info(todo,warn(ignoring(specialize=Specialize)))). |
600 | | - |
601 | | -eval_20(_Eq,RetType,Depth,Self,['py-dot-call!',[Arg1,Arg2|Specialize]|Args],Res):- is_list(Args), !, |
602 | | - maplist(as_prolog_x(Depth,Self), Args , Adjusted),!, |
603 | | - make_py_dot(Arg1,Arg2,Specialize,SymRes), |
604 | | - py_call_method_and_args_sig(RetType,Specialize,SymRes,Adjusted,Res). |
605 | | -eval_40(Eq,RetType,Depth,Self,['py-dot-call',Sym|Args],Res):- |
606 | | - eval_20(Eq,RetType,Depth,Self,['py-dot-call!',Sym|Args],Res). |
| 577 | +eval_py_atom(_Eq,_RetType,_Depth,_Self,['py-atom',Arg,Type],Res):- |
| 578 | + must_det_ll((py_atom_type(Arg,Type,Res))). |
607 | 579 |
|
608 | 580 |
|
609 | 581 | was_py_call(Eq,RetType,Depth,Self,PyAtom,Sym,PArgs,ParamList,RRetType):- |
610 | | - atomic(PyAtom), py_is_callable(PyAtom), !, Sym = PyAtom, |
| 582 | + atomic(PyAtom), py_is_function(PyAtom), !, Sym = PyAtom, |
611 | 583 | into_param_types(Eq,RetType,Depth,Self,Sym,PArgs,ParamList,RRetType). |
612 | 584 | was_py_call(Eq,RetType,Depth,Self,[PyAtom|Args],Sym,PArgs,ParamList,RRetType):- fail, PyAtom == 'py-atom',!, |
613 | 585 | eval_py_atom(Eq,RetType,Depth,Self,[PyAtom|Args],Sym), |
|
684 | 656 | op_to_pred_call_ret(PyAtom,Pred2,Ret3):- is_list(PyAtom),!, |
685 | 657 | maybe_trace(unknown) ,eval_py_atom(_Eq,_RetType,_Depth,_Self,PyAtom,Res),!,op_to_pred_call_ret(Res,Pred2,Ret3). |
686 | 658 | op_to_pred_call_ret(PyAtom,Pred2,Ret3):- |
687 | | - py_is_callable(PyAtom), !, Sym = PyAtom, |
| 659 | + py_is_function(PyAtom), !, Sym = PyAtom, |
688 | 660 | Pred2= py_call_method_and_args(Sym), |
689 | 661 | Ret3= py_metta_return_value(). |
690 | 662 |
|
|
1432 | 1404 | '=u='(X0,Y0) :- (X0 = Y0). |
1433 | 1405 | '=will'(X0,Y0) :- \+ \+ (X0 = Y0). |
1434 | 1406 | % alpha equivelant |
1435 | | -'=alpha'(X0,Y0) :- equal_enough_for_test_renumbered(alpha_equ,X0,Y0),!. |
| 1407 | +'=alpha'(X0,Y0) :- equal_enough_for_test_renumbered(alpha_equ,X0,Y0). |
1436 | 1408 | % like =alpha, however it actualyl also unifies (if they were alpha) |
1437 | 1409 | '=alpha-unify'(X0,Y0) :- '=alpha'(X0,Y0), blend_vars(X0,Y0). |
1438 | 1410 |
|
|
1771 | 1743 | eval_10(Eq,RetType,Depth,Self,['switch',A,CL|T],Res):- !, |
1772 | 1744 | eval_10(Eq,RetType,Depth,Self,['case',A,CL|T],Res). |
1773 | 1745 |
|
1774 | | -:- set_prolog_flag(gc,false). |
1775 | | - |
1776 | | -eval_10(Eq,RetType,Depth,Self,I,Res):- fail, |
1777 | | - once(metta_to_metta_body_macro_recurse(eval10,I,O)),I\=@=O,!, |
1778 | | - eval_10(Eq,RetType,Depth,Self,O,Res). |
1779 | | - |
1780 | 1746 | eval_10_disabled(Eq,RetType,Depth,Self,[P,X|More],YY):- fail, is_list(X),X=[_,_,_],simple_math(X), |
1781 | 1747 | eval_selfless_2(X,XX),X\=@=XX,!, eval_20(Eq,RetType,Depth,Self,[P,XX|More],YY). |
1782 | 1748 | % if there is only a void then always return nothing for each Case |
|
2048 | 2014 | eval_args(Eq,RetType,Depth,Self,['container-unify',Arg1,Arg2|Args],Res). |
2049 | 2015 | % 3) Otherwise, default to using `if-unify` for the unify operation. |
2050 | 2016 | eval_10(Eq,RetType,Depth,Self,['unify',Arg1,Arg2|Args],Res):- !, |
2051 | | - eval_args(Eq,RetType,Depth,Self,['if',['metta-unify',Arg1,Arg2]|Args],Res). |
| 2017 | + eval_args(Eq,RetType,Depth,Self,['if-unify',Arg1,Arg2|Args],Res). |
2052 | 2018 |
|
2053 | 2019 | eval_10(Eq,RetType,Depth,Self,['container-unify',Arg1,Arg2,Then|ElseL],Res):- !, |
2054 | 2020 | ((metta_container_sub_part(Arg1,Part),eval_args_true(Eq,'Bool',Depth,Self,['==',Part,Arg2])) |
|
2365 | 2331 | if_or_else(get_type(Depth,Other,Val,Type),Type='%Undefined%'), %term_singletons(Type,[]), %Type\==[], Type\==Val,!, |
2366 | 2332 | do_expander(Eq,RetType,Type,TypeO). |
2367 | 2333 |
|
2368 | | -%eval_20(Eq,RetType,Depth,Self,['length',L],Res):- !, eval_args(Eq,RetType,Depth,Self,L,LL), !, (is_list(LL)->length(LL,Res);Res=1). |
| 2334 | +eval_20(Eq,RetType,Depth,Self,['length',L],Res):- !, eval_args(Eq,RetType,Depth,Self,L,LL), !, (is_list(LL)->length(LL,Res);Res=1). |
2369 | 2335 | eval_20(Eq,RetType,Depth,Self,['CountElement',L],Res):- !, eval_args(Eq,RetType,Depth,Self,L,LL), !, (is_list(LL)->length(LL,Res);Res=1). |
2370 | 2336 |
|
2371 | 2337 | eval_20(_Eq,_RetType,_Depth,_Self,['get-metatype',Val],TypeO):- !, |
|
2537 | 2503 |
|
2538 | 2504 | with_scope(Eq,RetType,Depth,Self,Goal):- |
2539 | 2505 | %grab_scope([eq=WEq,retType=WRetType,depth=WDepth,self=WSelf]), |
2540 | | - setup_call_cleanup(push_scope([eq=Eq,retType=RetType,depth=Depth,self=Self]), |
| 2506 | + setup_call_cleanup(push_scope([eq = Eq,retType=RetType,depth=Depth,self=Self]), |
2541 | 2507 | Goal, |
2542 | | - pop_scope([eq=Eq,retType=RetType,depth=Depth,self=Self])). |
| 2508 | + pop_scope([eq = Eq,retType=RetType,depth=Depth,self=Self])). |
2543 | 2509 |
|
2544 | 2510 |
|
2545 | 2511 |
|
2546 | 2512 | ppp_default_value(self,V):- current_self(V), nocut. |
2547 | | -ppp_default_value(depth,StackMax):- current_prolog_flag(max_tagged_integer,MaxTI),option_else('stack-max',StackMax,MaxTI). |
| 2513 | +ppp_default_value(depth,0). % current_prolog_flag(max_tagged_integer,MaxTI),option_else('stack-max',StackMax,MaxTI). |
| 2514 | +%ppp_default_value(depth,StackMax):- current_prolog_flag(max_tagged_integer,MaxTI),option_else('stack-max',StackMax,MaxTI). |
2548 | 2515 | ppp_default_value(retType,_). |
2549 | | -ppp_default_value(eq,=). |
| 2516 | +ppp_default_value((eq),(=)). |
2550 | 2517 |
|
2551 | 2518 |
|
2552 | | -peek_scope(Eq,RetType,Depth,Self):- peek_scope([eq=Eq,retType=RetType,depth=Depth,self=Self]). |
| 2519 | +peek_scope(Eq,RetType,Depth,Self):- peek_scope([eq = Eq,retType=RetType,depth=Depth,self=Self]). |
2553 | 2520 | peek_scope(List):- maplist(peek_scope_item,List). |
2554 | | -peek_scope_item(N=V):- peek_scope_item(N,V). |
| 2521 | +peek_scope_item(N=V):- peek_scope_item(N,V),!. |
2555 | 2522 |
|
2556 | 2523 | peek_scope_item(N,V):- peek_current_scope(N,V),!. |
2557 | 2524 | peek_scope_item(N,V):- ppp_default_value(N,V),!. |
|
2562 | 2529 | first_of([V|_],V):-!. |
2563 | 2530 | first_of(V,V). |
2564 | 2531 |
|
2565 | | -push_scope(Eq,RetType,Depth,Self):- must_det_lls(push_scope([eq=Eq,retType=RetType,depth=Depth,self=Self])). |
2566 | | -push_scope(List):- maplist(push_scope_item,List). |
2567 | | -push_scope_item(N=V):- push_scope_item(N,V),!. |
| 2532 | +must_det_lls_cf(G):- call(G),!. |
| 2533 | +must_det_lls_cf(G):- trace,call(G),!. |
| 2534 | +push_scope(Eq,RetType,Depth,Self):- push_scope([eq = Eq,retType=RetType,depth=Depth,self=Self]). |
| 2535 | +push_scope([]). push_scope([H|T]):- ignore((push_scope_item(H),push_scope(T))). |
| 2536 | +push_scope_item(N=V):- !, push_scope_item(N,V),!. |
| 2537 | +push_scope_item(NV):- trace, print(pi(NV)). |
2568 | 2538 | push_scope_item(N,V):- push_current_scope(N,V),!. |
2569 | | -push_current_scope(N,V):- nb_current(N,List)->nb_setval(N,[V|List]),nb_setval(N,[V]). |
| 2539 | +push_current_scope(N,V):- (notrace(nb_current(N,List))->nb_setval(N,[V|List]),nb_setval(N,[V])),!. |
2570 | 2540 |
|
2571 | 2541 |
|
2572 | | -pop_scope(Eq,RetType,Depth,Self):- pop_scope([eq=Eq,retType=RetType,depth=Depth,self=Self]). |
| 2542 | +pop_scope(Eq,RetType,Depth,Self):- pop_scope([eq = Eq,retType=RetType,depth=Depth,self=Self]). |
2573 | 2543 | pop_scope(List):- maplist(pop_scope_item,List). |
2574 | 2544 | pop_scope_item(N=V):- pop_scope_item(N,V). |
2575 | | -pop_scope_item(N,V):- pop_current_scope(N,V),!. |
| 2545 | +pop_scope_item(N,V):- peek_current_scope(N,V),!. |
2576 | 2546 | pop_scope_item(N,V):- ppp_default_value(N,V),!. |
2577 | 2547 |
|
2578 | 2548 |
|
|
2759 | 2729 | %eval_args(Eq,RetType,Depth,Self,X,Y):- eval_20(Eq,RetType,Depth,Self,X,Y)*->true;Y=[]. |
2760 | 2730 |
|
2761 | 2731 | %eval_20(Eq,RetType,Depth,_,_,_):- Depth<1,!,fail. |
2762 | | -%eval_20(Eq,RetType,Depth,_,X,Y):- overflow_depth(3,Depth), !, ground(X), (Y=X). |
| 2732 | +%eval_20(Eq,RetType,Depth,_,X,Y):- Depth<3, !, ground(X), (Y=X). |
2763 | 2733 | %eval_20(Eq,RetType,_Dpth,_Slf,X,Y):- self_eval(X),!,Y=X. |
2764 | 2734 |
|
2765 | 2735 | % Kills zero arity functions eval_20(Eq,RetType,Depth,Self,[X|Nil],[Y]):- Nil ==[],!,eval_args(Eq,RetType,Depth,Self,X,Y). |
|
3288 | 3258 | % Macro Functions |
3289 | 3259 | %eval_20(Eq,RetType,Depth,_,_,_):- Depth<1,!,fail. |
3290 | 3260 | /* |
3291 | | -eval_40(_Eq,_RetType,Depth,_,X,Y):- overflow_depth(3,Depth), !, fail, ground(X), (Y=X). |
| 3261 | +eval_40(_Eq,_RetType,Depth,_,X,Y):- Depth<3, !, fail, ground(X), (Y=X). |
3292 | 3262 | eval_40(Eq,RetType,Depth,Self,[F|PredDecl],Res):- |
3293 | 3263 | fail, |
3294 | 3264 | Depth>1, |
|
3342 | 3312 | eval_40(Eq,RetType,Depth, Self,['py-atom'|Args],Res):- !, |
3343 | 3313 | eval_py_atom(Eq,RetType,Depth,Self,['py-atom'|Args],Res). |
3344 | 3314 |
|
3345 | | -eval_40(Eq,RetType,Depth,Self,['py-dot'|Args],Res):- !, |
3346 | | - eval_py_atom(Eq,RetType,Depth,Self,['py-dot'|Args],Res). |
3347 | | - |
| 3315 | +eval_40(_Eq,_RetType,_Depth,_Self,['py-dot',Arg1,Arg2| _Specialize],Res):- !, |
| 3316 | + make_py_dot(Arg1,Arg2,Res). |
3348 | 3317 | eval_40(_Eq,_RetType,_Depth,_Self,['py-type',Arg],Res):- !, |
3349 | 3318 | must_det_ll((py_type(Arg,Res))). |
3350 | 3319 | eval_40(_Eq,_RetType,_Depth,_Self,['py-eval',Arg],Res):- !, |
3351 | 3320 | must_det_ll((py_eval_string(Arg,Res))). |
3352 | 3321 |
|
3353 | | -eval_40(Eq,RetType,Depth,Self,['length',L],Res):- fail, !, eval_args(Depth,Self,L,LL), |
| 3322 | +eval_40(Eq,RetType,Depth,Self,['length',L],Res):- !, eval_args(Depth,Self,L,LL), |
3354 | 3323 | (is_list(LL)->length(LL,Res);Res=1), |
3355 | 3324 | check_returnval(Eq,RetType,Res). |
3356 | 3325 |
|
|
3368 | 3337 | */ |
3369 | 3338 | %eval_40(Eq,RetType,_Dpth,_Slf,['==',X,Y],Res):- !, subst_args(Eq,RetType,_Dpth,_Slf,['==',X,Y],Res). |
3370 | 3339 |
|
3371 | | -eval_20(_Eq,_RetType,_Depth,_Self,['==', X,Y],_):- X\=@=Y,fail. |
3372 | | -eval_20(_Eq,_RetType,_Depth,_Self,['==', X,Y],_):- X=@=Y, X\==Y,!,fail. |
3373 | 3340 | eval_20(_Eq,_RetType,_Depth,_Self,['==', X,Y],TF):- (var(X) , var(Y)), !, as_tf(X==Y,TF),!. |
3374 | 3341 | eval_40(_Eq,_RetType,_Depth,_Self,['==', X,Y],TF):- (var(X) , var(Y)), !, as_tf(X==Y,TF),!. |
3375 | 3342 |
|
3376 | | - |
3377 | 3343 | eval_40(Eq,RetType,Depth,Self,['==',X,Y],TF):- !, |
3378 | 3344 | ignore(get_operator_typedef(Self,'==',2,[XType,YType],RetType)), |
3379 | 3345 | eval_until_eq_tf(['=='],Eq, XType, YType, Depth,Self, X, Y, TF). |
|
3390 | 3356 | same_terms(X,Y):- \+ compound(X), X==Y. |
3391 | 3357 | % Main evaluation predicate with full caching |
3392 | 3358 |
|
3393 | | -%eval_40(=,_RetType,_,_,['make-var'|Types],Var):- !, 'mx__1_0+_make-var'(Types,Var). |
3394 | | -%eval_40(=,_RetType,_,_,['bless-var',Var|Types],Var):- !, 'mx__1_1+_bless-var'(Var,Types,Var). |
3395 | | - |
3396 | | - |
3397 | | -transpiler_peek(Sym,Len,Type,Fn, Len, exactArgs):- |
3398 | | - if_t((var(Sym)),ignore(transpiler_predicate_store(_, Sym,_ , _, _, _, _))), |
3399 | | - nonvar(Sym), |
3400 | | - if_t((var(Len)),ignore(transpiler_predicate_store(_,Sym,[Len],_, _, _, _))), |
| 3359 | +transpiler_peek(Sym,Len,Type,Fn):- |
| 3360 | + transpiler_predicate_store(_, Sym, [Len], _, _, _, _), |
3401 | 3361 | if_t(var(Type),member(Type,['mx','mi','mc'])), |
3402 | | - if_t(var(Len),between(1,10,Len)), |
3403 | 3362 | format(atom(Fn),'~w__1_~w_~w',[Type,Len,Sym]), |
3404 | 3363 | succ(Len,LenP1), current_predicate(Fn/LenP1), |
3405 | | - ok_call_predicate(Sym,Len,Type). |
| 3364 | + nop(ok_call_predicate(Sym,Len)). |
3406 | 3365 |
|
3407 | | -transpiler_peek(Sym,2,'mi',Fn, 2, exactArgs):- |
3408 | | - nonvar(Sym), |
3409 | | - atom_concat('mi__1_2_',Sym,Fn),current_predicate(Fn/3), |
3410 | | - \+ transpiler_predicate_store(_, Sym, [2], _, _, _, _), |
3411 | | - ok_call_predicate(Sym,Len,Type). |
3412 | | - |
3413 | | -transpiler_peek(Sym,Len,Type,Fn, Min, restAsList):- |
3414 | | - between(0,Len, Min), |
3415 | | - if_t(var(Type),member(Type,['mx','mi','mc'])), |
3416 | | - format(atom(Fn),'~w__1_~w+_~w',[Type,Min,Sym]), |
3417 | | - succ(Min,N1),succ(N1,LenP1), current_predicate(Fn/LenP1), |
3418 | | - ok_call_predicate(Sym,Len,Type). |
3419 | | - |
3420 | | -transpiler_peek(Sym,Len,Type,Fn, Min, restAsList):- |
3421 | | - between(0,Len, Min), |
3422 | | - if_t(var(Type),member(Type,['mx','mi','mc'])), |
3423 | | - format(atom(Fn),'~w_n_~w__~w',[Type,Min,Sym]), |
3424 | | - succ(Min,N1),succ(N1,LenP1), current_predicate(Fn/LenP1), |
3425 | | - ok_call_predicate(Sym,Len,Type). |
3426 | 3366 |
|
3427 | 3367 |
|
3428 | 3368 | ok_call_predicate(Sym,Min, _Type):- |
3429 | | - if_t(nb_current('eval_in_only', interp), \+ symbol_impl_exists(interp,Sym,Len)). |
| 3369 | + \+ transpiler_predicate_store(_,Sym,[Min],_,_,_,_), |
| 3370 | + \+ transpiler_predicate_nary_store(_,Sym,Min,_,_,_,_,_,_), |
| 3371 | + \+ transpiler_clause_store(Sym,[Min],_,_,_,_,_,_,_). |
| 3372 | + |
3430 | 3373 |
|
3431 | 3374 | eval_20(Eq, RetType, Depth, Self, [Sym | Args], Res) :- symbol(Sym), is_list(Args), |
3432 | | - len_or_unbound(Args, Len), |
3433 | | - transpiler_peek(Sym,Len,'mi',Fn, Min, AsList), |
3434 | | - jiggle_args(Args,Res,Len,Min,AsList,PArgs), |
| 3375 | + length(Args, Len), |
| 3376 | + memoize_tf(transpiler_peek(Sym,Len,'mi',Fn)), |
| 3377 | + append(Args, [Res], PArgs),!, |
3435 | 3378 | with_metta_ctx(Eq, RetType, Depth, Self, [Sym | Args], apply(Fn, PArgs)). |
3436 | 3379 |
|
3437 | 3380 | jiggle_args(Args,Ret,LenIsMin,LenIsMin,exactArgs,PArgs):- !, append(Args, [Ret], PArgs). |
|
3442 | 3385 | jiggle_append(Left,Right,Ret,exactArgs,PArgs):- append(Left, [Ret], PArgs), !, must_unify(Right,[]). |
3443 | 3386 |
|
3444 | 3387 | eval_20(Eq, RetType, Depth, Self, [Sym | Args], Res) :- symbol(Sym), is_list(Args), |
3445 | | - len_or_unbound(Args, Len), |
3446 | | - transpiler_peek(Sym,Len,'mx',Fn, Min, AsList), |
3447 | | - jiggle_args(Args,Res,Len,Min,AsList,PArgs), |
| 3388 | + length(Args, Len), |
| 3389 | + memoize_tf(transpiler_peek(Sym,Len,'mx',Fn)), |
| 3390 | + append(Args, [Res], PArgs),!, |
3448 | 3391 | with_metta_ctx(Eq, RetType, Depth, Self, [Sym | Args], apply(Fn, PArgs)). |
3449 | 3392 |
|
3450 | 3393 | eval_40(Eq,RetType,Depth,Self,[Sym|Args],Res):- symbol(Sym), is_list(Args), |
3451 | | - len_or_unbound(Args,Len), |
3452 | | - transpiler_peek(Sym,Len,'mc',Fn, Min,AsList), |
3453 | | - jiggle_args(Args,Res,Len,Min,AsList,PArgs), |
| 3394 | + length(Args,Len), |
| 3395 | + memoize_tf(transpiler_peek(Sym,Len,'mc',Fn)), |
| 3396 | + append(Args,[Res],PArgs),!, |
3454 | 3397 | with_metta_ctx(Eq,RetType,Depth,Self,[Sym|Args],apply(Fn,PArgs)). |
3455 | 3398 |
|
3456 | 3399 |
|
|
4005 | 3948 | if_t(between(401,420,Depth),writeq(a(B0))), |
4006 | 3949 | if_t(between(397,400,Depth),(writeq(b(B0)),trace)), |
4007 | 3950 | if_t(between(392,397,Depth),(writeq(c(B0)),maybe_trace(unknown),fail)), |
4008 | | - if_t(overflow_depth(380,Depth),(writeq(f(B0)),fail)). |
| 3951 | + if_t(Depth<380,(writeq(f(B0)),fail)). |
4009 | 3952 | */ |
4010 | 3953 |
|
4011 | 3954 | %eval_defn_failure(_Eq,_RetType,_Depth,_Self,X,X):- !. |
|
4534 | 4477 |
|
4535 | 4478 |
|
4536 | 4479 |
|
4537 | | - |
0 commit comments