MapleTA
ToString
convert an expression to a string and escape special characters
Calling Sequence
Parameters
Description
Examples
Compatibility
ToString( expr )
ToString( expr, sequence=true )
expr
-
anything
sequence
truefalse (optional) default is false
dotm
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,
expr≔1,2,3,a string,$X
s≔MapleTA:-ToString⁡expr
s≔[[1, 2, 3], \x22a string\x22, `\x24X`]
expr2≔parse⁡s,statement
expr2≔1,2,3,a string,$X
evalb⁡expr=expr2
true
This example shows the difference between a sequence of strings and a single string.
MapleTA:-ToString⁡1,2,3,4,5,6,sequence=true
[1, 2],[3, 4],[5, 6]
MapleTA:-ToString⁡1,2,3,4,5,6,sequence=false
[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
s1≔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
p⁡3
27
parse⁡s2,statement
p
After parsing, the old value of p is restored
9
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`))
parse⁡s,statement
HEIGHT⁡6'2" tall
The MapleTA[ToString] command was introduced in Maple 18.
For more information on Maple 18 changes, see Updates in Maple 18.
See Also
examples/Quiz
Download Help Document