Skip to content

Commit 22f9473

Browse files
committed
faster function index lookup
1 parent 345306c commit 22f9473

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

prolog/metta_lang/metta_eval.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,12 @@
606606
is_list(Args),!,
607607
Y=[Fn|RArgs], mapl_eval_args(Eq,RetType,Depth,Self,Args,RArgs).
608608

609+
610+
eval_10(Eq,RetType,Depth,Self,[V|VI],[V|VO]):- V==':',is_list(VI),!,
611+
mapl_eval_args(Eq,RetType,Depth,Self,VI,VO).
612+
eval_10(Eq,RetType,Depth,Self,[V|VI],VO):- is_list(V),V=[HV,_,_],HV==':',is_list(VI),!,
613+
mapl_eval_args(Eq,RetType,Depth,Self,[V|VI],VO).
614+
609615
eval_10(Eq,RetType,Depth,Self,[Sym|Args],Y):- \+ atom(Sym), !,
610616
maplist(as_prolog_x(Depth,Self), [Sym|Args] , [ASym|Adjusted]),
611617
eval_20(Eq,RetType,Depth,Self, [ASym|Adjusted], Y),sanity_check_eval(eval_20_not_atom,Y).

prolog/metta_lang/metta_interp.pl

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,13 +4151,10 @@
41514151
% ?- load_hook1(my_load, '&corelib', '=', head, body).
41524152

41534153
% load_hook1(_Load, '&corelib', _Eq, _H, _B) :- !.
4154-
load_hook1(Load, Self, Fact) :-
4155-
% Skip processing if the `metta_interp` flag is not set to `ready`.
4156-
% \+ is_metta_interp_ready,
4157-
% debug_info(assert_hooks,load_hook_not_ready(Load, Self, Fact)),
4158-
%fail,
4159-
!,
4160-
woc(load_hook_compiler(Load, Self, Fact)).
4154+
4155+
load_hook1(_Load, Self, [Eq,H,B]) :-
4156+
Eq == '=', assertz_if_new(metta_function_asserted(Self,H,B)),fail.
4157+
41614158

41624159
load_hook1(Load, Self, Fact) :-
41634160
% Ensure the Metta compiler is ready for use.
@@ -4166,6 +4163,13 @@
41664163
woc(load_hook_compiler(Load, Self, Fact)).
41674164
load_hook1(Load, Self, Fact):-
41684165
%debug_info(assert_hooks,not_use_metta_compiler(Load, Self, Fact)),
4166+
woc(load_hook_compiler(Load, Self, Fact)),!.
4167+
load_hook1(Load, Self, Fact) :-
4168+
% Skip processing if the `metta_interp` flag is not set to `ready`.
4169+
% \+ is_metta_interp_ready,
4170+
% debug_info(assert_hooks,load_hook_not_ready(Load, Self, Fact)),
4171+
%fail,
4172+
!,
41694173
woc(load_hook_compiler(Load, Self, Fact)).
41704174

41714175
metta_atom_asserted_hook(Self,Assertion):-
@@ -4450,6 +4454,15 @@
44504454
% @arg X The context or space.
44514455
% @arg Y The atom to check.
44524456
%
4457+
dont_bother(Atom):- Atom=@=[_, :, _].
4458+
dont_bother(Atom):- Atom=@=[=, [_, _], _]. % maybe
4459+
dont_bother(Atom):- Atom=@=[=, [_, _, _], _].
4460+
dont_bother(Atom):- Atom = [V1, [Colon, Thing, V2], V3], Colon==':', nonvar(Thing),maplist(var,[V1,V2,V3]).
4461+
4462+
metta_atom_added(_KB, Atom) :- dont_bother(Atom),!,fail.
4463+
metta_atom_added(X, [Eq,A,B]) :- Eq =='=', !,
4464+
woct(metta_function_asserted(X,A,B)).
4465+
44534466
metta_atom_added(X, Y) :- nocut,
44544467
% Check if the atom was explicitly asserted.
44554468
metta_atom_asserted_ocw(X, Y).
@@ -4491,10 +4504,6 @@
44914504
transform_about(Fact, Rule, Cond), Cond=='True',!,
44924505
fact_store(KB, Rule, Fact, Cond).
44934506
*/
4494-
dont_bother(Atom):- Atom=@=[_, :, _].
4495-
dont_bother(Atom):- Atom=@=[=, [_, _, _], _].
4496-
dont_bother(Atom):- Atom=@=[=, [_, _], _]. % maybe
4497-
dont_bother(Atom):- Atom = [V1, [Colon, Thing, V2], V3], Colon==':', nonvar(Thing),maplist(var,[V1,V2,V3]).
44984507

44994508
metta_atom0(_Inherit,_KB, Atom) :- dont_bother(Atom),!,fail.
45004509

@@ -4801,8 +4810,7 @@
48014810
% metta_eq_def(Eq,KB,H,B):- ignore(Eq = '='),metta_atom(KB,[Eq,H,B]).
48024811
metta_eq_def(Eq, KB, H, B) :-
48034812
ignore(Eq = '='),
4804-
metta_atom0(inherit([KB]),KB,[EQ, H, B]),
4805-
EQ == Eq.
4813+
metta_atom0(inherit([KB]),KB,[Eq, H, B]).
48064814

48074815
% Original commented-out code, retained as-is for potential future use:
48084816
% metta_defn(KB,Head,Body):- metta_eq_def(_Eq,KB,Head,Body).

0 commit comments

Comments
 (0)