Creating symbols from strings

### 25.5.4 Creating symbols from strings

Variable and function names are symbols, namely sequences of characters, which are different from strings. For example, you can have a variable named abc, but not "abc". The make_symbol command turns a string into a symbol; for example make_symbol("abc") is the symbol abc.

#### Examples

make_symbol("abc"):=3

then:

abc

3 |  |  |  |  |  |  |  |  |  |

The variable abc will have the value 3. Similarly for functions:

make_symbol("sin")(pi/4)

√ |
2
2

which is equal to sinπ/4.

##### Creating arrays of symbols.

The symbol_array command is used for creating multidimensional arrays of symbols.

- symbol_array takes two mandatory arguments and one optional argument:
  - str, a template string for symbol names.
  - dim=n1,n2,…,nm, a sequence of m positive integers.
  - Optionally, purge, the symbol.
- symbol_array(str,dim ⟨,purge ⟩) returns an array with m dimensions n1,n2,…,nm with indexed symbols as elements. Symbols are created from the template string str by appending indices. Template string may contain m instances of the character ’%’, kth of which serves as the placeholder for the kth dimension index. If placeholders are omitted, indices are simply appended in case m=1, while in case m>1 they are separated from str and each other by the underscore (’_’). If purge is given, then the already assigned symbols are purged, otherwise a warning is printed for each such symbol.
- The indices are in accordance with the current syntax mode (they are either 0- or 1-based).

#### Examples

symbol_array("x",5)

| ⎡ ⎣ | x0,x1,x2,x3,x4 | ⎤ ⎦

symbol_array("a",2,3)

⎡ ⎢ ⎣ |
a0,0 | a0,1 | a0,2
a1,0 | a1,1 | a1,2
| ⎤ ⎥ ⎦

maple_mode(1):; symbol_array("a%%",2,3)

[[a11,a12,a13],[a21,a22,a23]] |  |  |  |  |  |  |  |  |  |

maple_mode(0):; s:=symbol_array("a%b%c%",2,3,4)

| ⎡ ⎢ ⎢ ⎣ |
⎡ ⎢ ⎢ ⎣ |
a0b0c0 | a0b0c1 | a0b0c2 | a0b0c3
a0b1c0 | a0b1c1 | a0b1c2 | a0b1c3
a0b2c0 | a0b2c1 | a0b2c2 | a0b2c3
| ⎤ ⎥ ⎥ ⎦
| , |
⎡ ⎢ ⎢ ⎣ |
a1b0c0 | a1b0c1 | a1b0c2 | a1b0c3
a1b1c0 | a1b1c1 | a1b1c2 | a1b1c3
a1b2c0 | a1b2c1 | a1b2c2 | a1b2c3
| ⎤ ⎥ ⎥ ⎦
| ⎤ ⎥ ⎥ ⎦

s[1][2][3]

a1b2c3 |  |  |  |  |  |  |  |  |  |