Skip to content

Commit d45e3c3

Browse files
committed
[fix] Improve type system depth handling with overflow_depth/1 and correct type propagation in get_type_each/4 and get_value_type/4
1 parent 69ace54 commit d45e3c3

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

prolog/metta_lang/metta_types.pl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@
574574
is_PyObject(Val), !, 'PyObject' = PyObject.
575575
get_type_each(Depth, _Slf, _Type, _) :-
576576
% Fail if recursion depth is exhausted.
577-
Depth < 1, !, fail.
577+
overflow_depth(Depth), !, fail.
578578
% get_type(Depth, Self, Val, Type) :- is_debugging(eval),
579579
% ftrace(get_type_each(Depth, Self, Val, Type)),
580580
% fail.
@@ -584,7 +584,7 @@
584584
% Handle state monad expressions.
585585
notrace(is_valid_nb_state(Expr)), !,
586586
if_or_else(state_decltype(Expr, Type), nonvar(Type)),
587-
('get-state'(Expr, Val), !, Depth2 is Depth - 1,
587+
('get-state'(Expr, Val), !, deepen(Depth, Depth2),
588588
get_value_type(Depth2, Self, Val, Type)).
589589
get_type_each(_Dpth, Self, Var, Type) :-
590590
% Retrieve type from variable attributes.
@@ -801,7 +801,7 @@
801801
symbolic_list_concat([Type, _ | _], ':', Val).
802802
get_type_symb(Depth, Self, Op, Type) :-
803803
% Evaluate arguments if the operator is defined.
804-
Depth2 is Depth - 1,
804+
deepen(Depth, Depth2),
805805
eval_args(Depth2, Self, Op, Val),
806806
Op \=@= Val, !,
807807
get_type(Depth2, Self, Val, Type).
@@ -859,7 +859,7 @@
859859
% Curried Op
860860
get_type_cmpd(Depth,Self,[[Op|Args]|Arg],Type,curried(W)):-
861861
symbol(Op),
862-
Depth2 is Depth-1,
862+
deepen(Depth, Depth2),
863863
get_type_cmpd(Depth2,Self,[Op|Args],Type1,W),
864864
get_type(Depth2,Self,Arg,ArgType),
865865
ignore(sub_var_safely(ArgType,Type1)->true;
@@ -894,14 +894,14 @@
894894
List\==[],
895895
\+ badly_typed_expression(Depth,Self,List),
896896
is_list(List),
897-
Depth2 is Depth-1,
897+
deepen(Depth, Depth2),
898898
maplist(get_type(Depth2,Self),List,Types),
899899
\+ badly_typed_expression(Depth,Self,Types).
900900
901901
*/
902902
get_type_cmpd(Depth,Self,EvalMe,Type,Eval_First):-
903903
needs_eval(EvalMe),
904-
Depth2 is Depth-1,
904+
deepen(Depth, Depth2),
905905
eval_args_for_type(Depth2,Self,EvalMe,Val),
906906
get_type_cmpd_eval(Depth2,Self,EvalMe,Val,Type,Eval_First).
907907
get_type_cmpd(_Dpth,_Slf,_Cmpd,[],unknown).
@@ -985,14 +985,14 @@
985985
get_value_type(_Dpth,Self,List,Type):- is_list(List),metta_type(Self,List,LType),last_element(LType,Type), nonvar(Type),
986986
is_type(Type).
987987
988-
get_value_type(Depth,_Slf,Type,Type):- Depth<1,!.
988+
get_value_type(Depth,_Slf,Type,Type):- overflow_depth(Depth),!.
989989
get_value_type(_Dpth,Self,List,Type):- is_list(List),metta_type(Self,Type,['->'|List]).
990-
get_value_type(Depth,Self,List,Types):- List\==[], is_list(List),Depth2 is Depth-1,maplist(get_value_type(Depth2,Self),List,Types).
990+
get_value_type(Depth,Self,List,Types):- List\==[], is_list(List),deepen(Depth, Depth2),maplist(get_value_type(Depth2,Self),List,Types).
991991
get_value_type(_Dpth,Self,Fn,Type):- symbol(Fn),metta_type(Self,Fn,Type),!.
992-
%get_value_type(Depth,Self,Fn,Type):- nonvar(Fn),metta_type(Self,Fn,Type2),Depth2 is Depth-1,get_value_type(Depth2,Self,Type2,Type).
992+
%get_value_type(Depth,Self,Fn,Type):- nonvar(Fn),metta_type(Self,Fn,Type2),deepen(Depth, Depth2),get_value_type(Depth2,Self,Type2,Type).
993993
%get_value_type(Depth,Self,Fn,Type):- Depth>0,nonvar(Fn),metta_type(Self,Type,Fn),!. %,!,last_element(List,Type).
994994
995-
%get_value_type(Depth,Self,Expr,Type):-Depth2 is Depth-1,
995+
%get_value_type(Depth,Self,Expr,Type):-deepen(Depth, Depth2),
996996
% eval_args(Depth2,Self,Expr,Val),
997997
% Expr\=@=Val,get_value_type(Depth2,Self,Val,Type).
998998
@@ -1003,7 +1003,7 @@
10031003
%get_value_type(Depth,_Slf,Cmpd,Type):- compound(Cmpd), functor(Cmpd,Type,1),!.
10041004
%get_value_type(_Dpth,_Slf,Cmpd,Type):- \+ ground(Cmpd),!,Type=[].
10051005
%get_value_type(_Dpth,_Slf,_,'%Undefined%'):- fail.
1006-
%get_value_type(Depth,Self,Val,Type):- Depth2 is Depth-1, get_type_equals(Depth2,Self,Val,Type).
1006+
%get_value_type(Depth,Self,Val,Type):- deepen(Depth, Depth2), get_type_equals(Depth2,Self,Val,Type).
10071007
*/
10081008

10091009
%! as_prolog(+I, -O) is det.

0 commit comments

Comments
 (0)