1
$\begingroup$
SyntaxInformation[f] = {"ArgumentsPattern" -> {}};
f[] := 0;

After one ClearAll[f] or ClearAll["`*"], f remains black. It takes two to turn f blue, and it can't be in the same cell: just running ClearAll[f];ClearAll[f] is not enough. Yet one ClearAll is enough to clear FullDefinition[f].

In fact, the line f[] := 0; is extraneous; all that's needed is to define SyntaxInformation[f].

Is this a bug? Is there anything I can run once to turn everything blue?

$\endgroup$
3
  • 2
    $\begingroup$ Seems like a bug to me. I didn't look into this too much, but it looks like the front-end is informed about the symbol removal before the syntax-information stuff is updated. This probably confuses the front-end abojt the status of the symbol. As a workaround, clearing the syntax-information before clearing the symbol works for me: SyntaxInformation[f]=.; ClearAll[f] $\endgroup$
    – Lukas Lang
    Commented Jun 30, 2021 at 11:46
  • $\begingroup$ @LukasLang Can I enter something to clear all syntax information I've defined before a ClearAll["`*"]? $\endgroup$
    – H.v.M.
    Commented Jul 1, 2021 at 7:58
  • 1
    $\begingroup$ Something like Quiet[Unset@*SyntaxInformation@*Symbol /@ Names["`*"]] should do the job $\endgroup$
    – Lukas Lang
    Commented Jul 1, 2021 at 8:00

2 Answers 2

3
$\begingroup$

I've found some other cases where similar behavior occurs.

In a fresh kernel we run

BeginPackage["myP`"];
f::usage = "";
g::usage = "";
SyntaxInformation[f] = {"ArgumentsPattern" -> {}};
f[] := 1;
g[] := 1;
EndPackage[];

in a notebook. In this case even repeated calls to ClearAll[f,g] leave the symbols as black. In instead of ClearAll we use Remove[f,g] then g turns blue but f does not, even after repeated calls to Remove[f,g].

But if after removing the symbols you refer to them, say with Print[f], the symbol suddenly turns blue everywhere, but this new symbol is in the Global` context, and running the package cell will lead to a shadowing warning.

From what I've noticed, this happens when SyntaxInformation is used on a symbol, and this definition is added to DefaultValues in that way. Manually setting via DefaultValues[f] = {"thing" -> "thing2"} doesn't seem to have the same behavior.

$\endgroup$
2
  • 2
    $\begingroup$ This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. You can also add a bounty to draw more attention to this question. - From Review $\endgroup$
    – bbgodfrey
    Commented Sep 19 at 3:30
  • $\begingroup$ @bbgodfrey It does seem like a relevant set of examples that provides more perspective on the nature of the problem (so I upvoted). $\endgroup$ Commented Sep 19 at 15:05
0
$\begingroup$

It's a bug. From Wolfram Technical Support: "I have reproduced the issue and have reported it to our developers."

Workaround, from the comments by Lukas Lang: SyntaxInformation[f]=.; ClearAll[f] or Quiet[Unset@*SyntaxInformation@*Symbol /@ Names["`*"]]; ClearAll["`*"].

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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