Previous Up Next

10.4.4  Using strings as names

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 # operator will turn a string into a symbol; for example (#"abc") is the symbol abc.

If you enter

a := "abc"; (#a) := 3

or

(#"abc") := 3

then the variable abc will have the value 3. Entering #a will still give you abc; you can get 3 with eval(#a).

Similarly for functions. If you enter

b := "sin"; (#b)(pi/4)

or

(#"sin")(pi/4)

you will get

1/sqrt(2)

which is sin(pi/4).


Previous Up Next