9
$\begingroup$

Usually, when I define a function and then use it later, the function name is colored in black. But every once in a while, the function color is blue, both in its definition and when I use it later. The blue colored functions work as expected. I can't find any difference in the way I define them or any pattern. What does the blue coloring mean?

$\endgroup$
0

2 Answers 2

8
$\begingroup$

The difference in color depends on whether or not it is a recognized symbol: black indicates it is recognized, blue indicates that it is not. For a symbol to be recognized, it has had to have been input to the kernel, i.e. it has to have been included in an executed cell. I have had problems in the past when quitting and restarting the kernel where the highlighter doesn't begin to work again, so every user defined symbol is blue regardless of its state. But, I don't think I encountered it very often in v.7; it was more of a v.6 problem. (I just started using v.8, so I have no experience with it.)

$\endgroup$
4
  • 3
    $\begingroup$ The problem is still there in v8.04. For large notebooks with many symbols, some symbols remain blue after repeated executions although expressions containing such symbols execute without problem. $\endgroup$
    – kglr
    Commented Nov 21, 2011 at 21:06
  • $\begingroup$ @kguler, true, they still execute fine, it's just the syntax highlighter that decides to stop working. I probably saw it less in v.7, as I had to kill the kernel less often. Both, I and Mathematica got better. $\endgroup$
    – rcollyer
    Commented Nov 21, 2011 at 21:08
  • 1
    $\begingroup$ I am using version 8 for students, and it appears that I am experiencing this bug. Thank you! $\endgroup$
    – Jand
    Commented Nov 21, 2011 at 23:05
  • $\begingroup$ I'm seeing this bug right now in version 10. My notebook is not "large". $\endgroup$
    – Alan
    Commented May 18, 2015 at 22:08
6
$\begingroup$

I remember being confused by this when I first started out. As rcollyer notes, black means that it is either a command or a variable that contains information, blue means that it is not recognized at all. Try this:

testVariable="5"

When you execute it, testVariable will turn from blue to black. Now, if you're coding and need to call on testVariable, it will appear as black - if you misspelled it, as testvariable, it would appear as blue. i.e. Print[testVariable] will lead to 5 as an output. A good quick way to see what's going on.

Now try this (note: it will clear all of your currently defined variables!):

Clear["Global`*"]

Note that dynamically, testVariable will turn back to blue. It no longer holds anything, and you could not use it in any of your other commands. If you ran Print[testVariable] again without executing your earlier commands, it would not print 5 (rather, just 'testVariable') because testVariable is now empty.

$\endgroup$