Difference between revisions of "Common MathObject Properties"

From WeBWorK_wiki
Jump to navigation Jump to search
(Add comment about Context flags also being valid properties)
(Add Reference Tables category)
 
Line 102: Line 102:
   
 
[[Category:MathObjects]]
 
[[Category:MathObjects]]
  +
[[Category:Reference Tables]]

Latest revision as of 07:51, 13 August 2012

There are a number of properties that are common to all MathObejcts, as described below. Note that these properties apply to all MathObjects, but not every MathObject will have all of them defined. Some classes have additional properties, and many of these are listed in the documentation for the individual MathObject Classes. You set or get the value of a property of a MathObject as you would a property for any Perl object, using the -> operator with the MathObject on the left and the propery name in braces on the right. E.g.,

   $x = $mo->{property};
   $mo->{property} = $x;

In addition to the properties listed below, you can also set any of the Context flags listed in the Context flags documentation page as properties of a MathObject. In this case, the value will override that stored in the Context, but for that MathObject only. For example, you could set the tolerance on a Real, or the limits for a Formula in that way.

Properties Common to All Classes

Option Description Default
$mo->{context} A reference to the Context object under which the MathObject was created. Even if the Context is changed, the MathObject will continue to operate within its original Context. Context()
$mo->{equation} A reference to the Formula object from which a MathObject was created (if it was the result of evaluating a Formula). parent Formula
$mo->{correct_ans} The string to use for the correct answer when students request answers (after the due date). This is set automatically by undef
$mo->{data} A reference to an array containing the information defining the MathObject (e.g., the coordinates of a Point, the elements of a List, the intervals in a Union, or the real and imaginary parts of a Complex number. object data
$mo->{format} A printf-style string indicating how real numbers should be formatted for display. If the format ends in #, then trailing zeros are removed after the number is formatted. Example: "%.4f" would format numbers using 4-place decimals. "%g"
$mo->{open} For list-type objects (e.g., Points, Vectors, Matrices, Sets), the symbol to use at the left of the object when it is displayed. See specific class page
$mo->{close} For list-type objects (e.g., Points, Vectors, Matrices, Sets), the symbol to use at the right of the object when it is displayed. See specific class page
$mo->{noinherit} A reference to an array of property names that will not be included when a copy of a MathObject is made. This includes things like text_values and f for Formulas, and other values that are maintained automatically by the object. object specific
$mo->{isValue} When creating subclasses of MathObject classes, you may need to set this value so that the MathObject library will recognize your object class as belonging to the Value package. undef
$mo->{isClass}
E.g., $mo->{isVector}
When creating a subclass of a MathObject class, you may need to set this so that the MathObjects library will properly recognize your object as being of the given type when it does type-matching for things like comparisons with student answers, and so on. The Class can be any of the MathObject class names, e.g, $mo->{isReal}. undef
$mo->{ans_name}
$mo->{ans_rows}
$mo->{ans_cols}
These are used by the $mo->ans_array method to store information about the name used for the answer array, and its size. undef
$mo->{format_options} This is a reference to a hash that specifies options for the answer array layout, including the characters to use for the left and right delimiters and the separator in answer arrays. It provides values for open, close, and sep; the defaults are dependent on the class, and correspond to the open and close delimiters for the object, and either comma or blank as the separator, depending on the class. object specific

Variables and Constants

Variable Description Default
%Value::Type A hash containing type definitions needed for the values of Parser::Item objects. Use
TEXT(join(',',lex_sort(keys(%Value::Type))));

in the PG labs to get a list of the available types.

$Value::answerPrefix The answer name prefix to use for answer arrays created by the ans_array() method. "MaTrIx"
$Value::CMP_ERROR
$Value::CMP_WARNING
$Value::CMP_MESSAGE
Error values used with $context->setError() to indicate the severity of the error in answer checkers. 2
3
4