Reading the comments in this answer has motivated me to request a full solution to part of this problem.
What I'd like is an efficient solution that returns True
if there exist an OwnValue
and False
in all other cases. This narrow behavior mirrors what folks coming from other programming languages expect of asking if something has a value or not.
A solution needs to be able to handle symbols with any number of OwnValue
, UpValues
, DownValues
, SubValues
, NValues
, and FormatValues
. The only evalution that should occur is that required to get the value of the symbol's OwnValue
.
Motivation
My motivation for this request is twofold.
- There have been many queries on this topic, but none that appear to be specific enough to narrow down to one correct interpretation. I hope this question solves that.
- The behavior requested mirrors the behavior of most programming languages that folks are familiar with. That is, when we think of a symbol/"variable" having a value, we really mean to ask if the symbol has some
OwnValues
or not. Yes there are other interpretations of what it means to have aValueQ
that does not do extra evaluations, but this question does not cover them.
ValueQ
consistent with Mathematica's evaluation semantics - but it turn out to not be very useful in practice, since it triggers even trivial evaluations. $\endgroup$