String (MathObject Class)

From WeBWorK_wiki
Revision as of 17:01, 2 August 2012 by Dpvc (talk | contribs) (Created page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The String Class

The String class adds the ability to have special words or phrases be recognized by the MathObjects library. The two pre-defined words are DNE (for "does not exist") and NONE. By default, strings are not case sensitive, so dne and DNE (and Dne, and dNe, etc.) are all considered to be the same thing. The allowed strings are part of the Context, and you can add your own (or remove the two pre-defined ones), and you can make case-sensitive strings if you desire. See the String Context changes section for details.

   $ans = String("DNE");
   $ans = Compute("DNE");
   
   $ans = Compute("DNE,NONE");  # a list of strings

If a string answer is used where something other than a number could have been the answer (e.g., as a response to "At what points [math](x,y)[/math] is [math]\sqrt{x^2+y^2}[/math] undefined?"), then you should indicate the type of answer that might be expected when you create the answer checker by setting the typeMatch parameter to an instance of that type. E.g.,

   ANS(String("NONE")->cmp(typeMatch => Point(0,0)));

This will make sure that syntax checking and error messages are appropriate for the kind of answer that the student might submit.