3
$\begingroup$

Mathematica Version 11.2 desktop / Windows 10 Pro 64-bit

(* Assume y is undefined. *)

(* ?y and ??y leave y undefined. *)

?y

Information::notfound: Symbol y not found.

??y

Information::notfound: Symbol y not found.

(* AtomQ[y] has a side effect of defining y. *)

In[3]:= AtomQ[y]

Out[3]= True

In[5]:= ??y

Global`y

Why does AtomQ[y] define y?

Is this "By Design" i.e. a carefully thought out deliberate feature?

One would think that if y is not defined, AtomQ[y] would output this as an error.

Why else would one be using AtomQ[y] unless they thought y was already defined.

It seems like a dangerous side effect which makes debugging a nightmare.

Is there a property of the Kernel to enable or disable functions like AtomQ from defining symbols?

In general, which built-in functions leave symbols undefined and which do not?

Thanks in advance.

$\endgroup$
4
  • $\begingroup$ The creation and removal of symbols in contexts is described in the tutorial reference.wolfram.com/language/tutorial/BasicObjects.html. I'm not sure "define" is the right term to describe what happens. For instance Definition[y] returns Null, if you haven't given y any definitions or attributes, even though the name "y" is added to the "Global`" context. $\endgroup$
    – Michael E2
    Nov 26, 2017 at 21:12
  • $\begingroup$ Invoking foo[bar] puts both of foo and bar into the name space, in whatever is the current Context. But it does not mean either one has become "defined' in the sense of having DownValues or the like associated to them. $\endgroup$ Nov 26, 2017 at 21:31
  • 1
    $\begingroup$ It doesn't define it. It creates the symbol. Simply saying y creates the symbol y. $\endgroup$
    – Szabolcs
    Nov 26, 2017 at 22:11
  • $\begingroup$ I think linked topic answers your doubts and provides much more background. Let me know if you disagree with closing. $\endgroup$
    – Kuba
    Nov 27, 2017 at 8:39

1 Answer 1

4
$\begingroup$

This has nothing to do with AtomQ. Constructing an expression containing a symbol automatically gives it a definition. It doesn't even need to be evaluated. It acquires a presence in some context (usually Global), but not a value.

"Definition" isn't a formal Mathematica concept. Is a symbol that exists in some context "defined"? Yes, in the sense implied by this question, but no in the sense of having a value.

$\endgroup$
2
  • $\begingroup$ @Kuba As the comments above imply, "definition" isn't a formal Mathematica concept. Is a symbol that exists in some context "defined"? Yes, in the OP's sense, but no in the sense of having a value. $\endgroup$
    – John Doty
    Nov 27, 2017 at 12:53
  • $\begingroup$ Thanks for the edit $\endgroup$
    – Kuba
    Nov 27, 2017 at 15:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.