A.28 library(occurs): Finding and counting sub-terms
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(occurs): Finding and counting sub-terms
          • contains_term/2
          • contains_var/2
          • free_of_term/2
          • free_of_var/2
          • occurrences_of_term/3
          • occurrences_of_var/3
          • sub_term/2
          • sub_var/2
          • sub_term_shared_variables/3
    • Packages
Availability::- use_module(library(occurs)).(can be autoloaded)
Source[det]sub_term_shared_variables(+Sub, +Term, -Vars)
If Sub is a sub term of Term, Vars is bound to the list of variables in Sub that also appear outside Sub in Term. Note that if Sub appears twice in Term, its variables are all considered shared.

An example use-case is refactoring a large clause body by introducing intermediate predicates. This predicate can be used to find the arguments that must be passed to the new predicate.