When I type
Remove["Global`*"]
foo[] := Module[{Subscript[a, 1] = "x"}, 0];
foo[]
I get the expected error "only assignments to symbols are allowed". I understand the error.
But why I do not get the same error when I type the same assignment in the notebook?
Remove["Global`*"]
Subscript[a, 1] = "x"
No error and no beep.
What is the difference? I'm using version 8.04 on Windows.
Update
The non-localized trick shown by Szabolcs answer worked for me on a demo. Here is a screen shot of the result. What I was trying to do is to typeset some information about a solver, some matrix equation, and I thought why not take advantage of MatrixForm
and Grid
's nice way of typesetting things, and display the information right there in the demo screen as an option? This is easier than putting it in the text section below where it can hard to get to as I have so many such things.
Here is an example of the code and the result. You can see I did not localized these symbols in the module which builds this expression. I just started trying this idea, but so far I am happy that it worked. This below is only an example, not cleaned up, just wanted to see if the demo will work.