PLOGHELP DOLLAR Jonathan Laventhol, 28 June 1983 Revised by Kathryn Seifert September 1986 Library package for using variables to hold predicate names Keywords: predicate, variable, functor, clause, structure LIBRARY DOLLAR is a facility for using variables to hold predicate names. To make it available, type: ?- library(dollar). Once the library file is loaded, you can use the dollar symbol ('$') between a variable holding a predicate name and the arguments of the predicate. You can now use two forms of clauses with variable predicate names: in the first form, the arguments of the predicate are given in a list; in the second form, the arguments are specified normally. Both ?- X = member, X$(x, [a, b, x]). ?- X = member, X$[x, [a, b, x]]. are equivalent to ?- member(x, [a, b, x]). For the first of these forms the number of arguments must be known at the time the program is written. Moreover, none of the arguments should be instances of the functor ',' with 2 arguments (such a structure represents a pair; see HELP * PAIR). The list notation form can be used when the number of arguments is not known at the time the program is written. For instance: ?- ... X$[apple|Y], ... will cause the predicate whose name is the value of the variable X and whose arity is 1 + the length of the list Y to be invoked when the "$" goal is reached. The first argument will be the atom "apple", and Y must be instantiated to a list giving the rest of the arguments, ending in []. This form can also be used if you know the name of the predicate when the program is written, but don't know how many arguments it will take in every use, as in: ?- ... mother$X, ... If you want to use a predicate with known arity zero, there is no need to use the "$" mechanism at all. That is, ?- ... X, ... will work if X is bound to an atom when the goal is encountered. If the variable for the predicate name is uninstantiated when the "$" goal is executed, then a mishap results. By default, the dollar associates to the left, and has a precedence of 100 (for an explanation of operators and precedences see PLOGHELP * OP). -- RELATED DOCUMENTATION ---------------------------------------------- PLOGHELP * LIBRARIES Overview of Prolog library programs