convert an expression to a string and escape special characters
ToString( expr )
ToString( expr, sequence=true )
truefalse (optional) default is false
The ToString command converts the given expression to a string that has some characters encoded. The result is a string that is suitable for use by the parse command in order to get the given expression back. More importantly, the result is usable by the Maple T.A. built-in "maple" command used in writing question algorithms.
If the sequence option is set to true and the given expression is a sequence of more than one item, then a sequence of strings is returned. This sequence is suitable for use with the "switch" command in Maple T.A.
If the dotm option is set to true, then the output will not be human readable. However, the output will have more state information, such as assigned values of named procedures among other things.
This example shows a sample expression converted to a string and demonstrates the round-trip back through parse
expr ≔ 1,2,3,a string,
s ≔ MapleTA:-ToString⁡expr
s≔[[1, 2, 3], \x22a string\x22, `\x24X`]
expr2 ≔ parse⁡s,'statement'
This example shows the difference between a sequence of strings and a single string.
[1, 2],[3, 4],[5, 6]
[1, 2], [3, 4], [5, 6]
This example shows that the value of p is not encoded in the non-dotm conversion
p := proc(x) x^2; end;
p ≔ procxx^2end proc
s1 ≔ MapleTA:-ToString⁡p
s2 ≔ MapleTA:-ToString⁡p,'dotm'=true
s2≔MapleTA:-Builtin:-maple(StringTools:-SubstituteAll(\x22op(sscanf(&dquote:I\\&dquote:pf*6#%\\&dquote:xG6\\&dquote:6\\&dquote:F&*\x249\x24\\&dquote:\\&dquote:#F&F&F&F&&dquote:,&dquote:%m&dquote:))\x22, `&dquote:`, `\x22`))
Note that s1 only encoded p, while s2 has more information. Reassign p so we can see what happens when the s2 statement is parsed and executed.
p := proc(x) x^3; end;
p ≔ procxx^3end proc
After parsing, the old value of p is restored
Some magic must be done to work around double-quotes inside strings
s ≔ MapleTA:-ToString⁡HEIGHT⁡6'2" tall
s≔MapleTA:-Builtin:-maple(StringTools:-SubstituteAll(\x22HEIGHT(&dquote:6'2\\&dquote: tall&dquote:)\x22, `&dquote:`, `\x22`))
The MapleTA[ToString] command was introduced in Maple 18.
For more information on Maple 18 changes, see Updates in Maple 18.
Download Help Document