From a10395460e91015c9b17a6854e799d03d3a4d144 Mon Sep 17 00:00:00 2001 From: logicmoo Date: Mon, 30 Dec 2024 14:15:47 -0800 Subject: [PATCH] nb_current(evaling_args,t) to fix issue https://github.com/trueagi-io/metta-wam/issues/225 --- prolog/metta_lang/metta_eval.pl | 54 +++++++++++++-------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/prolog/metta_lang/metta_eval.pl b/prolog/metta_lang/metta_eval.pl index 4570682599..03307ba1ba 100755 --- a/prolog/metta_lang/metta_eval.pl +++ b/prolog/metta_lang/metta_eval.pl @@ -120,6 +120,8 @@ % is_self_eval_l_fa('=',2). % eval_20(Eq,RetType,Depth,Self,['quote',Eval],RetVal):- !, Eval = RetVal, check_returnval(Eq,RetType,RetVal). is_self_eval_l_fa('quote',_). +is_self_eval_l_fa('=',_):- nb_current(evaling_args,t). +is_self_eval_l_fa(':',_):- nb_current(evaling_args,t). is_self_eval_l_fa('Error',_). is_self_eval_l_fa('{...}',_). is_self_eval_l_fa('[...]',_). @@ -2361,29 +2363,31 @@ if_or_else(eval_maybe_host_predicate(Eq,RetType,Depth,Self,PredDecl,Res), if_or_else(eval_maybe_host_function(Eq,RetType,Depth,Self,PredDecl,Res), fail))). -eval_all_args:- fail, true_flag. +eval_all_args:- naive_eval_args. fail_missed_defn:- true_flag. fail_on_constructor:- true_flag. eval_adjust_args(Eq,RetType,ResIn,ResOut,Depth,Self,X,Y):- - if_or_else((eval_all_args,eval_adjust_args2(Eq,RetType,ResIn,ResOut,Depth,Self,X,Y)), - eval_adjust_args1(Eq,RetType,ResIn,ResOut,Depth,Self,X,Y)). + if_or_else((eval_all_args,eval_adjust_args_niavely(Eq,RetType,ResIn,ResOut,Depth,Self,X,Y)), + eval_adjust_args_precise(Eq,RetType,ResIn,ResOut,Depth,Self,X,Y)). -eval_adjust_args1(Eq,RetType,ResIn,ResOut,Depth,Self,[AE|More],[AE|Adjusted]):- +eval_adjust_args_precise(Eq,RetType,ResIn,ResOut,Depth,Self,[AE|More],[AE|Adjusted]):- adjust_args_90(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted). adjust_args_90(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted):- \+ is_debugging(eval_args),!, - adjust_args_9(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted). + adjust_args_91(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted). adjust_args_90(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted):- - if_or_else(adjust_args_9(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted), - if_or_else(with_debug(eval_args,adjust_args_9(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted), - if_or_else(More=Adjusted, + if_or_else(adjust_args_91(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted), + if_or_else(with_debug(eval_args, + adjust_args_91(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted), + if_or_else(More=Adjusted, if_or_else((trace, throw(adjust_args_9(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted)))))))). +adjust_args_91(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted):- + locally(nb_setval(evaling_args,t),adjust_args_9(Eq,RetType,ResIn,ResOut,Depth,Self,AE,More,Adjusted)). - -eval_adjust_args2(Eq,_RetType,ResIn,ResOut,Depth,Self,[AE|More],[AE|Adjusted]):- - maplist(must_eval_args(Eq,_,Depth,Self),More,Adjusted), +eval_adjust_args_niavely(Eq,_RetType,ResIn,ResOut,Depth,Self,[AE|More],[AE|Adjusted]):- + locally(nb_setval(evaling_args,t),maplist(must_eval_args(Eq,_,Depth,Self),More,Adjusted)), ResIn = ResOut. @@ -2702,7 +2706,6 @@ len_or_unbound(_,_). -:-if(true). :- nodebug(metta('defn')). eval_maybe_defn(Eq,RetType,Depth,Self,X,Res):- @@ -2743,32 +2746,16 @@ eval_defn_failure(Eq,RetType,Depth,Self,X,Y)). -eval_defn_success(Eq,RetType,Depth,Self,X,Y,XX,B0,USED):- +eval_defn_success(Eq,RetType,Depth,Self,XIn,ResOutY,XX,B0,USED):- + eval_adjust_args(Eq,RetType,Y,ResOutY,Depth,Self,XIn,X), X=XX, Y=B0, X\=@=B0, if_trace(e,color_g_mesg('#773700',indentq2(Depth,defs_used(USED)))), light_eval(Eq,RetType,Depth,Self,B0,Y),!. -eval_defn_failure(_Eq,_RetType,Depth,_Self,X,Res):- +eval_defn_failure(Eq,RetType,Depth,Self,X,Res):- if_trace(e,color_g_mesg('#773701',indentq2(Depth,defs_failed(X)))), - !, \+ fail_missed_defn, X=Res. - - -:-else. -eval_maybe_defn(Eq,RetType,Depth,Self,X,Y):- can_be_ok(eval_maybe_defn,X),!, - trace_eval(eval_defn_choose_candidates(Eq,RetType),'defn',Depth,Self,X,Y). + eval_constructor(Eq,RetType,Depth,Self,X,Res). + \+ fail_missed_defn. -eval_defn_choose_candidates(Eq,RetType,Depth,Self,X,Y):- - findall((XX->B0),get_defn_expansions(Eq,RetType,Depth,Self,X,XX,B0),XXB0L), - XXB0L\=[],!, - Depth2 is Depth-1, - if_trace((defn;metta_defn), - maplist(print_templates(Depth,' '),XXB0L)),!, - member(XX->B0,XXB0L), X=XX, Y=B0, X\=@=B0, - %(X==B0 -> trace; eval_args(Eq,RetType,Depth,Self,B0,Y)). - light_eval(Depth2,Self,B0,Y). -eval_defn_choose_candidates(_Eq,_RetType,_Depth,_Self,_X,_Y):- \+ is_debugging(metta_defn),!,fail. -eval_defn_choose_candidates(_Eq,_RetType,_Depth,_Self,X,_Y):- - color_g_mesg('#773700',write(no_def(X))),!,fail. -:- endif. pl_clause_num(Head,Body,Ref,Index):- clause(Head,Body,Ref), @@ -3052,3 +3039,4 @@ eval_evals(_Eq,_Depth,_Self,_RetType,X,X):-!. +