Details and Options
- ValueQ has attribute HoldAll.
- ValueQ[expr,Methodm] uses the specified method to determine if the expression has a value defined for it:
- Possible values for the option Method include:
Automatic automatic behavior "SymbolDefinitionsPresent" one or more symbols have any sort of definition present "TrialEvaluation" test if the expression changes after evaluation "OwnValuesPresent" one or more symbols have a non-empty OwnValues "Legacy" match behavior in Version 12.1 and earlier
- With the default method, Automatic, ValueQ[expr] effectively uses "OwnValuesPresent" if expr is a symbol and "SymbolDefinitionsPresent" otherwise.
Examplesopen allclose all
Basic Examples (2)
Check immediate and delayed values of symbols:
Expressions with head f give True whether or not they actually change:
"SymbolDefinitionsPresent" tests if a symbol has any sort of evaluation definitions associated with it:
"OwnValuesPresent" tests whether any symbol has a direct assignment:
"TrialEvaluation" tests if the input expression will change:
"SymbolDefinitionsPresent" tests whether any code will run, even if it leaves the value unchanged:
The Automatic method gives the same results as "OwnValuesPresent" for symbols:
It agrees with "SymbolDefinitionsPresent" for more general inputs:
Properties & Relations (3)
By default, ValueQ[symbol] only checks symbol for OwnValues, not other kinds of values:
ValueQ[x] is True because a value was assigned directory to x:
ValueQ[f] is False because f itself was not assigned a value:
For more general expressions, ValueQ checks for any kind of symbol definition:
If x is allowed to evaluate prior to entering ValueQ, the result for y will be given:
Pi evaluates to itself:
Use NumericQ to find out whether there is a numerical value defined:
Possible Issues (1)
Here x is evaluated before ValueQ sees it:
Use Unevaluated to preserve the HoldAll attribute:
Wolfram Research (1988), ValueQ, Wolfram Language function, https://reference.wolfram.com/language/ref/ValueQ.html (updated 2020).
Wolfram Language. 1988. "ValueQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/ValueQ.html.
Wolfram Language. (1988). ValueQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ValueQ.html