Difference between revisions of "String (MathObject Class)"
(Created page) |
m (Added eq comment) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | == |
+ | === 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 <code>DNE</code> (for "does not exist") and <code>NONE</code>. By default, strings are not case sensitive, so <code>dne</code> and <code>DNE</code> (and <code>Dne</code>, and <code>dNe</code>, 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 [[IntroductionToContexts#Context_changes_for_Strings| String Context changes]] section for details. |
+ | The String class adds the ability to have special words or phrases be recognized by the MathObjects library. The two pre-defined words are <code>DNE</code> (for "does not exist") and <code>NONE</code>. By default, strings are not case sensitive, so <code>dne</code> and <code>DNE</code> (and <code>Dne</code>, and <code>dNe</code>, 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 [[IntroductionToContexts#Context_changes_for_Strings| String Context changes]] section for details. Strings can be used in any Context. |
+ | |||
+ | |||
+ | === Creation === |
||
$ans = String("DNE"); |
$ans = String("DNE"); |
||
Line 7: | Line 7: | ||
$ans = Compute("DNE,NONE"); # a list of strings |
$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 <code>cmp()</code> method: |
||
+ | |||
+ | ANS(String("DNE")->cmp); |
||
+ | |||
+ | The String class supports the [[Answer_Checker_Options_(MathObjects)| common answer-checker options]], and the following additional options: |
||
+ | |||
+ | {| class="wikitable" |
||
+ | ! Option !! Description !! style="padding:5px" | Default |
||
+ | |- style="vertical-align: top" |
||
+ | | style="padding: 5px; white-space: nowrap" | <code>typeMatch => $object</code> |
||
+ | | style="padding: 5px" | 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., <code>"Value::Vector"</code>). |
||
+ | | style="text-align:center" | <code>1</code> |
||
+ | |} |
||
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 <code>typeMatch</code> parameter to an instance of that type. E.g., |
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 <code>typeMatch</code> parameter to an instance of that type. E.g., |
||
Line 13: | Line 30: | ||
This will make sure that syntax checking and error messages are appropriate for the kind of answer that the student might submit. |
This will make sure that syntax checking and error messages are appropriate for the kind of answer that the student might submit. |
||
+ | |||
+ | To test for equality of strings, use <code>eq</code>, not <code>==</code>. (This is a Perl thing.) |
||
+ | |||
+ | === 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: |
||
+ | |||
+ | {| class="wikitable" |
||
+ | ! Property !! Description !! style="padding:5px" | Default |
||
+ | |||
+ | |- style="vertical-align: baseline" |
||
+ | | style="padding: 5px; white-space: nowrap" | <code>$r->{caseSensitive}</code> |
||
+ | | style="padding: 5px" | Determines whether or not comparisons to other strings are case sensitive. |
||
+ | | style="text-align:center; padding:5px" | defined in Context |
||
+ | |||
+ | |} |
||
+ | |||
<br> |
<br> |
Latest revision as of 16:23, 17 June 2014
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.
To test for equality of strings, use eq
, not ==
. (This is a Perl thing.)
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 |