11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

26 • Chapter 2: Procedures, Variables, and Extending MapleExample 1The following application prompts the user for an answer to a question.> DetermineSign := proc(a::algebraic) local s;> printf("Is the sign of %a positive? Answer yes or no: ",a);> s := readline(terminal);> evalb( s="yes" or s = "y" );> end proc:> DetermineSign(u-1);Is the sign of u-1 positive?Answer yes or no: ytrueFor more details on the readline command, see sec-Information:tion 4.5.Reading Expressions from the TerminalYou can write procedures that interpret user input as a Maple expressionrather than a string. The readstat command reads one expression fromthe keyboard.readstat( prompt )The prompt is an optional string.> readstat("Enter degree: ");Enter degree: n-1;n − 1The user input for a readstat command must have a terminating semicolonor colon, or an error is raised.Advantages Unlike the readline command, which only reads one line,the readstat allows you to break a large expression across multiple lines.Another advantage of using the readstat command is that if there isan error in the input, the readstat command automatically repeats theprompt for user input.

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

Saved successfully!

Ooh no, something went wrong!