Difference between revisions of "String (MathObject Class)"

From WeBWorK_wiki
Jump to navigation Jump to search
(Break into sections, add Answer Checker, Methods, and Properties.)
m (Update Properties link)
Line 37: Line 37:
 
=== Methods ===
 
=== Methods ===
   
The String class supports the [[MathObject_Methods_and_Properties| common MathObject methods]]. There are no additional methods for this class.
+
The String class supports the [[Common MathObject Methods]]. There are no additional methods for this class.
   
   
 
=== Properties ===
 
=== Properties ===
   
The String class supports the [[MathObject_Methods_and_Properties| common MathObject properties]], and the following additional ones:
+
The String class supports the [[Common MathObject Properties]], and the following additional ones:
   
 
{| class="wikitable"
 
{| class="wikitable"

Revision as of 05:39, 6 August 2012

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. Strings can be used in any Context.


Creation

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


Answer Checker

As with all MathObjects, you obtain an answer checker for a String object via the cmp() method:

   ANS(String("DNE")->cmp);

The String class supports the common answer-checker options, and the following additional options:

Option Description Default
typeMatch => $object Specifies the type of object that the student should be allowed to enter (determines what constitutes a type mismatch error). Can be either a MathObject or a string that is the class of a MathObject (e.g., "Value::Vector"). 1

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.


Methods

The String class supports the Common MathObject Methods. There are no additional methods for this class.


Properties

The String class supports the Common MathObject Properties, and the following additional ones:

Property Description Default
$r->{caseSensitive} Determines whether or not comparisons to other strings are case sensitive. defined in Context