Skip to content

Commit

Permalink
nb_current(evaling_args,t) to fix issue trueagi-io#225
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Dec 30, 2024
1 parent 9983239 commit a103954
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions prolog/metta_lang/metta_eval.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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('[...]',_).
Expand Down Expand Up @@ -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.


Expand Down Expand Up @@ -2702,7 +2706,6 @@
len_or_unbound(_,_).


:-if(true).
:- nodebug(metta('defn')).

eval_maybe_defn(Eq,RetType,Depth,Self,X,Res):-
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -3052,3 +3039,4 @@
eval_evals(_Eq,_Depth,_Self,_RetType,X,X):-!.



0 comments on commit a103954

Please sign in to comment.