A programming question

"Norbert E. Fuchs" <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi

To collect all terms of the form skX/{0-N} – where X is a number 1, 2, ... and the term can have any number of arguments – that occur in Term I use the call

(*)   findall(Skolem, (subterm(Skolem, Term), functor(Skolem, Functor, _Arity), atom_chars(Functor, [s,k|_])), Skolems)

where

subterm(Term, Term) :-
  nonvar(Term).

subterm(Sub, Term):-
  nonvar(Term),
  functor(Term, _F, N),
  N > 0,
  subterm(N, Sub, Term).


subterm(N, Sub, Term):-
  arg(N, Term, Arg),       
  subterm(Sub, Arg).

subterm(N, Sub, Term):-
  N>1,
  N1 is N-1,
  subterm(N1, Sub, Term).


Since the call (*) occurs in several places in my program and is used very often, I wonder about its efficiency. 

Any suggestions how to speed up the call? Is replacing functor/3 by univ a good idea? Should I replace the general subterm/2 by a specialised form that takes the form of the subterm into account? 

Regards.

   --- nef
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.