I'm reading the book of Leonid Shifrin, and I love the way the book explains the core in Mathematica. As everything is an expression, now I understand that, there are no real function or variable in Mathematica. Function is such an indexed variable containing several rules.

So both function Sin and variable x are Symbol. Everything in Mathematica is Symbol, String, or Number. This principle helps me a lot.

f = Sin;
g = Sin[x];
{f[x], g[x]}

{Sin[x], Sin[x][x]}

Without this principle, a beginner can think that the function g equals to the function Sin[x]. So g[x] should return as Sin[x]. And he can think that the definition f = Sin is impossible because Sin should be expressed as a function Sin[something].

But here, we can see that Mathematica is very flexible. If we consider Sin as a variable, so assigning f = Sin is totally correct. And g[x] is not equal to Sin[x], but Sin[x][x]. I think this is a very basic thing, that a beginner should remember.

So many books on Mathematica don't explain these principles, they just teach how to use the command. But understanding the core in Mathematica for me is much more important, because it is the basic to master Mathematica programming style. Thank you Leonid Shifrin.

As now, I see that functions and variable are Symbol. Beside Symbol, could we use another type as a variable?
For example, I would like to have a list of 40 variables a1=1, a2=2, a3=3,... a40=40. But I don't want to use indexed variable a[1], a[2], a[3], a[40] because for me, it is just one variable a with several index.

Of course, the natural way is typing a1 = 1, a2 = 2, ... a40 = 40 manually. But how to do it in automatically in a loop or table way?

My first try is to generate "a1", "a2", ... "a40" as String.

"a" <> # & /@ ToString /@ Table[i, {i, 3}]

{"a1", "a2", "a3"}

But String can not be used as variable....

{"a1", "a2", "a3"} = {1, 2, 3}

Set::setraw: Cannot assign to raw object a1. >>

So how to generate a list of variable? a1, a2, a3...?

I try to use ToExpression to convert the String to Expression, I got a list of variable a1,a2,a3.

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.
If this question can be reworded to fit the rules in the help center, please edit the question.

2

Thanks for this, I really appreciate, and I am happy that the book works for you. Comments such as this show that writing the book was a good thing. But I see no question here. Our format on SE requires that one asks a question. Sorry, but we'll have to close this.
–
Leonid ShifrinDec 21 '13 at 22:14

Although I agree with you that one of the biggest problems is that the core principles of Mathematica are not understood by even some long-term users, the problem of your article is, that it is no question. We all have agreed on how posts should look on StackExchange. What can we do with your post now, except of just closing it? Please review the help and make suggestions. Maybe you can edit your post and make it a real question?
–
halirutanDec 21 '13 at 22:15

Therefore, it should not really have an impact on performance which version you choose. It is just that, as you have observed yourself, the first version with a[1] can be created more easily.

Nevertheless, there are ways to create a list a1, a2, .... If you want new, unique variable-names, one of the easiest methods is using Unique. Here is a short snip creating a table and showing you what was set

A disadvantage of this method is that Unique really takes the next free variable. When you know for sure that your variables a1, .. don't have a value, you can use Symbol to create the symbol from a string

While you may not like to use indexed variable, it is the most natural way to do what you want in Mathematica. But to satisfy your request, convert your created String to Symbol, then you can do the assignment.

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.