Explicit search targets

Some particularly complex searches can be expressed in aptitude using explicit targets. In normal search expressions, there is no way to refer to the package or version that is currently being tested. For instance, suppose that you want to search for all packages P that depend on a second package Q such that Q recommends P. Clearly you need to start out with a ?depends(...) term. But the term filling in the ... needs to somehow select packages that are identical to the one being matched against ?depends. When describing the goal above, I dealt with this by giving the packages names, calling them P and Q; terms with explicit targets do exactly the same thing. [17]

An explicit target is introduced by the ?for term:

Figure 2.13. Syntax of the ?for term

?for variable: pattern

This behaves exactly like pattern, but variable can be used within pattern to refer to the package or version that pattern is being matched against. You can use variable in two ways:

  1. The term ?= will match exactly the package or version indicated by the given variable. Specifically: if the corresponding ?for term is limited to a particular version, then ?= will match either that version (if ?= is limited) or the whole package; otherwise it will match any version of the package.

    See Example 2.2, “ Use of the ?= term. ” for an example of how to use ?=.

  2. The term ?bind(variable, pattern) will match any package or version if the value of variable matches against pattern.

    For ?-style terms, a shorthand form is available. The expression ?bind(variable, ?term[(args)]) can be replaced by ?variable:term(args).

    See Example 2.3, “Use of the ?bind term” for an example of how to use ?bind.



[17] Astute readers will note that this is essentially a way to explicitly name the variable in the λ-terms corresponding to the term. A typical term would have the form λ x . name-equals(x, pattern); giving this an explicit target makes x visible in the search language.