Symbols

The symbols we have discussed so far are generated following the same rules as identifiers for C++:

  1. The first character is either a letter or an underscore.
  2. All subsequent characters are either letters, digits or underscores.

In Maple, however, you can also generate a symbol that do not satisfy this description, and to do so, you simply have to wrap the characters in back quotes:

[> `a symbol`^2 + 3*`a symbol` + 1;

$\textit{a symbol }^2 + 2 \textit{a symbol} + 1$

[> eval( %, `a symbol` = 5 );

$36$

A symbol that does not require back-quotes is the same symbol if it happens to be wrapped in back-quotes:

[> evalb( x = `x` );

$true$

To include a back-quote, you simply escape it using the backslash character, and the backslash character is used to escape other common non-printing characters as well, just like strings:

[> `\`abc\``^2;

$\textit{`abc`}^2$

[> eval( %, `\`abc\`` = 10 );

$100$

There is little use of this, but awkwardly enough, what this means is that the empty-symbol is still a symbol:

[> ``^2 + 3*`` + 1;

$\textit{ }^2 + 3\textit{ } + 1$

[> eval( %, `` = 1 );

$5$

This is one place where this is used: to fake parentheses. For example, this automatically expands, and there is no way to stop this expansion:

[> 3*(x + 1);

$3x + 3$

Instead, have $3$ multiplied by the function `` applied to the argument (x + 1):

[> 3*``(x + 1);

$3(x + 1)$

This is used in the ifactor(...) function that factors integers:

[> ifactor( 1971 );

$(3)^3(73)$

In general, the lprint(...) function prints out the expression based on how it would be entered in the command prompt.

[> lprint( % );
``(3)^3*``(73)

In general, do not create symbols using back-quotes. There is nothing useful that can be achieved with this, and it leads to issues that may frustrate someone reading your Maple code.

On the other hand, this is a great way to obfuscate code: imagine trying to debug code with `` and ` \` ` and ` t` as variable names? The last would look just like the variable t, at least when displayed to the screen:

[> ` t` + t + `t `;

$t + t + t$

This can, however, also be achieved through escaped local variables (more on this later).