# Functions defined with numbers

If I have defined functions as "A1", "A2" ecc. then I have many function as A+number, can I define a For cycle to call these functions (they have all the same kind of arguments) once?

Something like

For[i<64, i == 0, i++, A"i"[]]


I don't know if it is possible.

• Table[ToExpression @ StringTemplate["A[]"] @ i, {i, 64}]. In general take a look at: 783
– Kuba
Commented Jan 8, 2018 at 15:32
• Why not define these functions as A[1], A[2] etc.? Commented Jan 8, 2018 at 15:40
• Thank you both, I have defined these functions as A[1] ecc... Now I am satisfied! Commented Jan 8, 2018 at 16:06

You can use Symbol function. For example:

For[i = 0, i < 64, i++, Symbol[StringTemplate["A"]@i][]]


Perhaps it will be faster than ToExpression. Also you can use auxiliary function:

A[i_] := A[i] = Symbol@StringTemplate["A"]@i

For[i = 0, i < 64, i++, A[i][]]


Previously calculated A[i_] results (symbols) are "cached" by A[i_] := A[i]=....

IMHO best way is to define array (or SparseArray) of functions. Then you can call functions directly by index without extra symbol lookup.