Skip to content

Commit

Permalink
eval_until_unify_self
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Dec 22, 2024
1 parent 128129f commit 6fedd51
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions prolog/metta_lang/metta_eval.pl
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,13 @@
unified(X,Y):- eval(X,XX),X\=@=XX,unified(Y,XX).
unified(X,Y):- eval(Y,YY),Y\=@=YY,unified(YY,X).

eval_until_unify([h_e|_],Eq,RetType,Depth,Self,X,Y):- var(Y),!,X==Y.
eval_until_unify([h_e|_],Eq,RetType,Depth,Self,X,Y):- var(X),!,X==Y.
eval_until_unify(Flags,Eq,RetType,Depth,Self,X,Y):-
eval_until_eq(Flags,Eq,RetType,Depth,Self,X,Y),!.
eval_until_unify(_Eq,_RetType,_Dpth,_Slf,X,X):- !.


eval_until_unify_self([h_e|_],Eq,RetType,Depth,Self,X,Y, Res):- var(Y),!,as_tf(X==Y, Res).
eval_until_unify_self([h_e|_],Eq,RetType,Depth,Self,X,Y, Res):- var(X),!,as_tf(X==Y, Res).
eval_until_unify_self(Flags,Eq,RetType,Depth,Self,X,Y):-
as_tf(eval_until_eq(Flags,Eq,RetType,Depth,Self,X,Y),Res).


eval_until_eq(_Flags,Eq,RetType,_Dpth,_Slf,X,Y):- X==Y,!,check_returnval(Eq,RetType,Y).
Expand Down Expand Up @@ -553,7 +556,7 @@
(eval_in_steps_some_change(Eq,RetType,Depth,Self,EXX,EXXO);EXXO=EXX).
eval_in_steps_some_change(Eq,RetType,Depth,Self,X,Y):-
append(L,[EX|R],X),is_list(EX),
eval_in_steps_some_change(Eq,RetType,Depth,Self,EX,EXX), EX\=@=EXX,
eval_in_steps_some_change(Eq,RetType,Depth,Self,EX,EXX), EX\=@=EXX,
append(L,[EXX|R],XX),
eval_in_steps_or_same(Eq,RetType,Depth,Self,XX,Y).

Expand Down Expand Up @@ -602,7 +605,7 @@
%eval_20(Eq,RetType,Depth,Self,['let',V,E,Body],BodyO):- !,eval_args(Eq,RetType,Depth,Self,E,V),eval_args(Eq,RetType,Depth,Self,Body,BodyO).
eval_20(Eq,RetType,Depth,Self,['let*',[],Body],RetVal):- !, eval_args(Eq,RetType,Depth,Self,Body,RetVal).
%eval_20(Eq,RetType,Depth,Self,['let*',[[Var,Val]|LetRest],Body],RetVal):- !,
% eval_until_unify(Flags,Eq,_RetTypeV,Depth,Self,Val,Var),
% eval_until_unify_self(Flags,Eq,_RetTypeV,Depth,Self,Val,Var),
% eval_20(Eq,RetType,Depth,Self,['let*',LetRest,Body],RetVal).
eval_20(Eq,RetType,Depth,Self,['let*',[[Var,Val]|LetRest],Body],RetVal):- !,
eval_20(Eq,RetType,Depth,Self,['let',Var,Val,['let*',LetRest,Body]],RetVal).
Expand Down Expand Up @@ -2283,10 +2286,18 @@
*/
%eval_40(Eq,RetType,_Dpth,_Slf,['==',X,Y],Res):- !, subst_args(Eq,RetType,_Dpth,_Slf,['==',X,Y],Res).

eval_20(Eq,RetType,Depth,Self,['==', X,Y],TF):- !,
eval_20(Eq,RetType,Depth,Self,['==', X,Y],Res):-
suggest_type(RetType,'Bool'),
(eval_until_unify([h_e,'=='],Eq,_SharedType,Depth,Self,X,Y)->TF='True';TF='False').
eval_until_unify_self([h_e,'=='],Eq,_SharedType,Depth,Self,X,Y, Res),
(Res=='False' -> (!, fail) ; fail).

%eval_40(Eq,RetType,_Depth,Self,[EQ,X,Y],TF):- fail, EQ=='==', !,
% suggest_type(RetType,'Bool'),
% as_tf(eval_until_unify(Eq,_SharedType, X, Y), TF).
eval_40(Eq,RetType,Depth,Self,['==',X,Y],TF):- !,
suggest_type(RetType,'Bool'),
as_tf(eval_until_eq(Eq,_SharedType, Depth,Self, X, Y), TF).

eval_20(Eq,RetType,Depth,Self,_Slf,['===',X,Y],TF):- !,
suggest_type(RetType,'Bool'),
as_tf(\+ \+ eval_until_unify(['==='],Eq,_SharedType,Depth,Self,X,Y), TF).
Expand Down

0 comments on commit 6fedd51

Please sign in to comment.