MapleTA - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Education : MapleTA Package : MapleTA/ToString

MapleTA

  

ToString

  

convert an expression to a string and escape special characters

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

ToString( expr )

ToString( expr, sequence=true )

Parameters

expr

-

anything

sequence

-

truefalse (optional) default is false

dotm

-

truefalse (optional) default is false

Description

• 

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.

Examples

This example shows a sample expression converted to a string and demonstrates the round-trip back through parse

expr1,2,3,a string,`$X`

expr:=1,2,3,a string,$X

(1)

sMapleTA:-ToStringexpr

s:=[[1, 2, 3], \x22a string\x22, `\x24X`]

(2)

expr2parses,'statement'

expr2:=1,2,3,a string,$X

(3)

evalbexpr=expr2

true

(4)

This example shows the difference between a sequence of strings and a single string.

MapleTA:-ToString1,2,3,4,5,6,'sequence'=true

[1, 2],[3, 4],[5, 6]

(5)

MapleTA:-ToString1,2,3,4,5,6,'sequence'=false

[1, 2], [3, 4], [5, 6]

(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

(7)

s1MapleTA:-ToStringp

s1:=p

(8)

s2MapleTA:-ToStringp,'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`))

(9)

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

(10)

p3

27

(11)

parses2,'statement'

p

(12)

After parsing, the old value of p is restored

p3

9

(13)

Some magic must be done to work around double-quotes inside strings

sMapleTA:-ToStringHEIGHT6'2" tall

s:=MapleTA:-Builtin:-maple(StringTools:-SubstituteAll(\x22HEIGHT(&dquote:6'2\\&dquote: tall&dquote:)\x22, `&dquote:`, `\x22`))

(14)

parses,statement

HEIGHT6'2" tall

(15)

Compatibility

• 

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

MapleTA

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam