Am 16.05.2010 17:22, schrieb Christian Wirth: > expand(X,ResListIn,[F/A|ResListOut]) :- > functor(X,F,A),clause(X,C),((C=true)->(ResListOut=ResListIn);(join_string([F,A,"rec"],"/",String1),(containsKey(String1)->(ResListOut=ResListIn,call(X));(expand(C,ResListIn,ResListOut))))). > > containsKey(Key) :- clause(logicStorage(Key,_)). > > logicStorage is a dynamic predicate and contains all recursive > predicates. The resolutionlist of those predicates should not be saved. > And ideas how to increase the speed further ? If requiered, i would also > be willing to make changes to the eclipse source code to have this > resolution list available. > > Instead of this: expand(X,ResListIn,[F/A|ResListOut]) :- functor(X,F,A), clause(X,C), ( C = true -> ResListOut=ResListIn ; join_string([F,A,"rec"],"/",String1), ( containsKey(String1) -> ResListOut=ResListIn, call(X) ; expand(C,ResListIn,ResListOut) ) ). I would use something like this: expand(X,ResListIn,[F/A|ResListOut]) :- ( clause(X,true) -> ResListOut=ResListIn ; functor(X,F,A), recursive(F,A) -> ResListOut=ResListIn, call(X) ; expand(C,ResListIn,ResListOut) ). 1. The clause body C is only needed for the check C=true. You can use clause(X,true) directly. 2. The use of join_string and containsKey seems expensive. Instead of forming a string and then testing for that you can test for F and A directly. You would need to rewrite containsKey, but I would consider replacing that dynamic predicate with a static one anyway: If the list of recursive predicates is known at the beginning, you can collect the Functor/Arity specifications and then compile corresponding facts (I used recursive(F,A) in the code above). By compiling them into a static predicate, access will be much faster than with a dynamic predicate. Depending on the number of recursive predicates, and therefore the specifications that need to be checked, storing them in a data structure that allows faster access than iterating over the facts should be considered even if the list of recursive predicates is not known a priori. Cheers, ThorstenReceived on Mon May 17 2010 - 06:31:45 CEST
This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET