|
1112 | 1112 | eval_20(Eq,RetType,Depth,Self,['cpu-time',Cond],Res):- !, ctime_eval(eval_args(Cond),eval_args(Eq,RetType,Depth,Self,Cond,Res)).
|
1113 | 1113 | eval_20(Eq,RetType,Depth,Self,['wall-time',Cond],Res):- !, wtime_eval(eval_args(Cond),eval_args(Eq,RetType,Depth,Self,Cond,Res)).
|
1114 | 1114 | eval_20(Eq,RetType,Depth,Self,['time!',Cond],['Time',Seconds,Res]):- !, wtimed_call(eval_args(Eq,RetType,Depth,Self,Cond,Res), Seconds).
|
1115 |
| -eval_20(Eq,RetType,Depth,Self,['print',Cond],Res):- !, eval_args(Eq,RetType,Depth,Self,Cond,Res),format('~N'),print(Res),format('~N'). |
| 1115 | +eval_20(Eq,RetType,Depth,Self,['print',Cond],Res):- !, eval_args(Eq,RetType,Depth,Self,Cond,Res),format('~N'),write_src_woi(Res),format('~N'). |
1116 | 1116 | % !(print! $1)
|
1117 | 1117 | eval_20(Eq,RetType,Depth,Self,['princ!'|Cond],Res):- !,
|
1118 | 1118 | maplist(eval_args(Eq,RetType,Depth,Self),Cond,Out),
|
|
2978 | 2978 |
|
2979 | 2979 | eval_20(Eq,RetType,Depth,Self,['unique',Eval],RetVal):- !,
|
2980 | 2980 | term_variables(Eval+RetVal,Vars),
|
2981 |
| - %no_repeat_variant_var(YY), |
2982 |
| - %no_repeats_var(YY), |
2983 |
| - no_repeats_var(variant_by_type,YY), |
| 2981 | + no_repeat_variant_var(YY), |
2984 | 2982 | eval_args(Eq,RetType,Depth,Self,Eval,RetVal),YY=Vars.
|
2985 | 2983 |
|
2986 |
| -eval_20(Eq,RetType,Depth,Self,['unique-by',P2,Eval],RetVal):- !, |
2987 |
| - no_repeats_var(call_as_p2(P2),YY), |
| 2984 | +no_repeat_variant_var(Var):- no_repeats_var(Var). |
| 2985 | +%no_repeat_variant_var(Var):- no_repeats_var(variant_by_type,Var). |
| 2986 | + |
| 2987 | +eval_30(_Eq,_RetType,_Depth,_Self,['unique-atom-by',P2,List],RetVal):- !, |
| 2988 | + unique_elements_by(P2,List,RetVal). |
| 2989 | + |
| 2990 | +unique_elements_by_xform(_, [], []). |
| 2991 | +unique_elements_by_xform(P2, [H|T], R) :- |
| 2992 | + eval_as_f2(P2, H, Key), |
| 2993 | + include(different_key(P2, Key), T, NewT), |
| 2994 | + unique_elements_by_xform(P2, NewT, RT), |
| 2995 | + R = [H|RT]. |
| 2996 | + |
| 2997 | +different_key(P2, Key, Elem) :- |
| 2998 | + call(P2, Elem, OtherKey), |
| 2999 | + Key \= OtherKey. |
| 3000 | + |
| 3001 | +/* |
| 3002 | +[1] 3 ?- unique_elements_by(==,[1,2,3,4,1,2,2],X). |
| 3003 | +X = [1, 2, 3, 4]. |
| 3004 | +
|
| 3005 | +[1] 4 ?- unique_elements_by(>,[1,2,3,4,1,2,2],X). |
| 3006 | +X = [1, 2, 3, 4]. |
| 3007 | +
|
| 3008 | +[1] 5 ?- unique_elements_by(<,[1,2,3,4,1,2,2],X). |
| 3009 | +X = [1, 1]. |
| 3010 | +
|
| 3011 | +[1] 6 ?- unique_elements_by(>,[4,2,3,4,1,2,2],X). |
| 3012 | +X = [4, 4]. |
| 3013 | +
|
| 3014 | +[1] 7 ?- unique_elements_by(>,[3,2,3,4,1,2,2],X). |
| 3015 | +X = [3, 3, 4]. |
| 3016 | +*/ |
| 3017 | +unique_elements_by(_, [], []). |
| 3018 | +unique_elements_by(P2, [H|T], [H|R]) :- |
| 3019 | + exclude(call_as_p2(P2, H), T, Filtered), |
| 3020 | + unique_elements_by(P2, Filtered, R). |
| 3021 | + |
| 3022 | +unnegate_f2(P2,_):- \+ compound(P2),!,fail. |
| 3023 | +unnegate_f2(not(P2),P2). |
| 3024 | +unnegate_f2([Not,P2|Nil],P2):- !,Nil==[],Not=='not'. |
| 3025 | + |
| 3026 | +must_use_eval(_,2):- !. |
| 3027 | +%must_use_eval(_,2):- fail. |
| 3028 | + |
| 3029 | +call_as_p2a(F2,A,B):- unnegate_f2(F2,P2),!, \+ call_as_p2(P2,A,B). |
| 3030 | +call_as_p2a(P2,A,B):- current_predicate(P2/2),!,call(P2,A,B). |
| 3031 | +call_as_p2a(P2,A,B):- current_predicate(P2/3),!,call(P2,A,B,RetVal),f2_success(RetVal,A,B). |
| 3032 | +call_as_p2a(F,X,Y):- must_use_eval(F,2), !, |
| 3033 | + once(eval([F,X,Y],RetVal)), |
| 3034 | + f2_success(RetVal,X,Y). |
| 3035 | +%call_as_p2(F2,A,B):- f2_to_p2(F2,P2),F2\==P2,!,call(P2,A,B). |
| 3036 | +call_as_p2a(F2,A,B):- f2_to_p3(F2,P3),F2\==P3,!,call(P3,A,B,RetVal),f2_success(RetVal,A,B). |
| 3037 | +call_as_p2a(F2,A,B):- eval_as_f2(F2,A,B,RetVal),f2_success(RetVal,A,B). |
| 3038 | + |
| 3039 | +f2_success(RetVal,A,B):- once(RetVal=='True';RetVal==A;RetVal==B). |
| 3040 | + |
| 3041 | +eval_as_f2(F2,A,B,RetVal):- current_predicate(F2/3),!,call(F2,A,B,RetVal),!. |
| 3042 | +eval_as_f2(F2,A,B,RetVal):- f2_to_p3(F2,P3),!,call(P3,A,B,RetVal). |
| 3043 | +eval_as_f2(F2,A,B,RetVal):- once(eval([F2,A,B],TF)), |
| 3044 | + (TF == 'True'-> RetVal=A ; |
| 3045 | + TF == 'False'-> fail ; RetVal = TF). |
| 3046 | + |
| 3047 | +f2_to_p2(F2,P2):- |
| 3048 | + transpiler_peek(F2,2,_,P2,_,exactArgs,Builtin), |
| 3049 | + interp_calls_module(Builtin). |
| 3050 | + |
| 3051 | +f2_to_p3(F2,P2):- |
| 3052 | + transpiler_peek(F2,2,_,P2,_,exactArgs,Builtin), |
| 3053 | + interp_calls_module(Builtin). |
| 3054 | + |
| 3055 | + |
| 3056 | +impl_module(Sym,Builtin):- |
| 3057 | + transpiler_predicate_nary_store(Builtin, Sym, _, _, _, _, _, _, _). |
| 3058 | +impl_module(Sym,Builtin):- |
| 3059 | + transpiler_predicate_store(Builtin,Sym,_,_,_,_,_). |
| 3060 | +impl_module(Sym,Builtin):- |
| 3061 | + transpiler_clause_store(Sym,_,_,_,_,_,_,_,_),Builtin = atomspace. |
| 3062 | + |
| 3063 | + |
| 3064 | +interp_calls_module(Builtin):- Builtin==code,!. |
| 3065 | +interp_calls_module(Builtin):- Builtin==stdlib,!. |
| 3066 | +interp_calls_module(Builtin):- Builtin==code_found,!. |
| 3067 | +interp_calls_module(Builtin):- Builtin==builtin, \+ option_value(compiler,full). |
| 3068 | +interp_calls_module(UserMod):- (UserMod==(user)), \+ option_value(compiler,false). |
| 3069 | + |
| 3070 | +eval_20(Eq,RetType,Depth,Self,['unique-by',F2,Eval],RetVal):- !, |
| 3071 | + no_repeats_var(call_as_p2(F2),YY), |
2988 | 3072 | eval_args(Eq,RetType,Depth,Self,Eval,RetVal),YY=RetVal.
|
2989 | 3073 |
|
2990 | 3074 |
|
|
0 commit comments