On Fri, 14 May 2010, Christian Wirth wrote: > I'm currently using pred(X) :- > functor(X,F,A),not(F==aPred),anotherCall(X), but i want to replace this > because speedup is very essential. It's probably best that you use a cut, as Joachim suggested. However, it's also worth pointing out that there's a faster way to do the "X is not of the form aPred(_)" test: instead of functor(X,F,A),not(F==aPred) you could write: X \= aPred(_) That is not exactly the same as functor(X,F,A),not(F==aPred) because it only matches aPred(_) (with arity one), not (for instance) aPred(_,_) (with arity two). But it'll be faster. If you wanted to really match all things that don't have the functor aPred, regardless of arity, you could do this: X=..Y, Y \= [aPred|_] That will be slower than the arity-one version, but probably faster than your code that uses functor/3. Joachim's suggestion using cut should be faster than either of them - and it'll continue to work even if you add additional clauses later and want to exclude those too. -- Matthew Skala, postdoctoral researcher, Universities of Toronto and Waterloo mskala_at_...203... mskala@...205... mskala@...206...Received on Sat May 15 2010 - 17:50:19 CEST
This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST