This module defines a constant and function that formalize the concept of a "metavariable." See the documentation for the Matching module for a definition of metavariables and how they relate to the concept of matching.
See
- metavariable - for marking certain symbols as metavariables
- containsAMetavariable() - for testing whether expressions contain metavariables
- metavariablesIn() - for computing an array of all metavariables within a given expression
- metavariableNamesIn() - for computing a set of all names of metavariables within a given expression
Source
Members
metavariable
To facilitate marking some Symbols as metavariables (in contrast to any Symbol not so marked), we declare a string constant that can be used with the isA() and asA() and makeIntoA() functions in the MathConcept class.
For example, to mark a symbol A
as a metavariable, one can import this
module (call it M
) and then call A.makeIntoA( M.metavariable )
. You
can later test to see if A
is a metavariable with
A.isA( M.metavariable )
.
Note, however, that only Symbol instances can be used as metavariables by the matching module. Although you can mark any LogicConcept as a metavariable this way, it is useless to do so, and other functions in this module will not recognize non-Symbols as metavariables.
Source
Methods
containsAMetavariable(LC) → {boolean}
A pattern is an Expression that may contain a metavariable. Hence all Expressions are patterns, though an Expression without any metavariables is a pattern only in a degenerate sense. But sometimes we need to know we are working with an Expression that does not contain a metavariable, that is, a non-pattern expression. This function is useful for detecting that case.
Recall that a metavariable is any Symbol that has been marked as a metavariable as described in the documentation for metavariable.
Parameters
-
LC
LogicConcept
the LogicConcept to test for whether it contains any metavariables
Returns
-
boolean
true if and only if
LC
contains no metavariables
Source
metavariableNamesIn(LC) → {Set}
Find the collection of metavariables appearing in the given LogicConcept, considering only their names as strings, not distinguishing one instance of, say, $x$, from another. Thus the result of this function will be a set that may have fewer elements than the array that would be returned by metavariablesIn() if it were called on the same input.
Parameters
-
LC
LogicConcept
where to search for metavariable names
Returns
-
Set
a JavaScript set of strings, each of which is the name of a metavariable appearing in the given
LC
Source
metavariablesIn(LC) → {Array}
Find the ordered list of all descendants of the given LogicConcept that are metavariables. In contrast to metavariableNamesIn(), this function returns the actual Symbol instances, not just their string names, and thus this list might be longer than what metavariableNamesIn() would return on the same input.
Parameters
-
LC
LogicConcept
where to search for metavariables
Returns
-
Array
a JavaScript array of all Symbol instances that are descendants of the given
LC
and that pass thes.isA( metavariable )
test. Note that a LogicConcept is considered a descendant of itself. The results appear in tree traversal order.