Skip to content

Commit

Permalink
Refactored metta_eval.pl:
Browse files Browse the repository at this point in the history
- Simplified get-ftype logic by removing redundant fallback clauses.
- Centralized type inference logic for cleaner and more efficient evaluation.
  • Loading branch information
TeamSPoon committed Jan 4, 2025
1 parent 507a539 commit 27d7a8e
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions prolog/metta_lang/metta_eval.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1559,19 +1559,8 @@
get_types(Depth,Self,Val,TypeO).

eval_20(Eq,RetType,Depth,Self,['get-ftype',Val],TypeO):- !,
if_or_else(get_ftype(Eq,RetType,Depth,Self,Val,TypeO),get_ftype_fallback(Eq,RetType,Depth,Self,Val,TypeO)).

get_ftypes(Eq,RetType,Depth,Self,Val,TypeO):-
if_or_else(get_ftype(Eq,RetType,Depth,Self,Val,TypeO),get_ftype_fallback(Eq,RetType,Depth,Self,Val,TypeO)).

get_ftype(_Eq,_RetType,Depth,Self,Val,TypeO):-
get_type(Depth,Self,Val,TypeO),is_list(TypeO),[Type|_]=TypeO,Type=='->'.
get_ftype(_Eq,_Type,_Depth,Self,[Op|Args],TypeO):- nonvar(Op), !,
once(len_or_unbound(Args,Len)),
get_operator_typedef(Self, Op, Len, ParamTypes, RetType), append(['->'|ParamTypes],[RetType],TypeO).
get_ftype(_Eq,_Type,_Depth,Self,Op,TypeO):-
between(0,8,Len),
get_operator_typedef(Self, Op, Len, ParamTypes, RetType), append(['->'|ParamTypes],[RetType],TypeO).
get_ftype(Eq,RetType,Depth,Self,Val,TypeO).


% use default self
eval_20(Eq,RetType,Depth,Self,['get-type',Val,Self],Type):- current_self(Self), !,
Expand Down

0 comments on commit 27d7a8e

Please sign in to comment.