11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.7 Conversion Commands • 189Conversion between strings and lists of integers is useful when Maplemust interpret parts of a stream of bytes as a character string, while itmust interpret other parts as individual bytes.In the following example, Maple converts a string to a list of integers.Then, it converts the same list, but with one entry changed to 0, back toa string. Notice that the string is truncated at the location of the 0.> convert("Test String",bytes);[84, 101, 115, 116, 32, 83, 116, 114, 105, 110, 103]> convert([84,101,115,116,0,83,116,114,105,110,103],bytes);“Test”Parsing Maple Expressions and StatementsThe parse command converts a string of valid Maple input to the correspondingMaple expression. The expression is simplified, but not evaluated.Use the parse command as follows.parse( string, options )The string argument is the string to be parsed. It must describe a Mapleexpression (or statement, see the following definition) by using the Maplelanguage syntax.You can supply one or more options to the parse command:statement This indicates that parse is to accept statements in additionto expressions. However, since Maple automatically evaluates statements,parse evaluates the string if you specify statement.nosemicolon Normally, parse supplies a terminating semicolon, “;” ifthe string does not end in a semicolon or a colon, “:”. If youspecify nosemicolon, this does not happen, and Maple generatesan unexpected end of input error if the string is incomplete. Thereadstat command, which uses readline and parse, makes use ofthis facility to allow multi-line inputs.If the string passed to parse contains a syntax error, parse generatesan error (which you can trap with traperror) of the following form.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!