Difference between revisions of "Common MathObject Properties"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created table of values)
Line 1: Line 1:
{{UnderConstruction}}
 
  +
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 [[:Category:MathObject_Classes|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 <code>-></code> operator with the MathObject on the left and the propery name in braces on the right. E.g.,
   
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.
 
  +
$x = $mo->{property};
  +
$mo->{property} = $x;
  +
  +
The common properties include:
  +
  +
{| class="wikitable"
  +
! Option !! Description !! style="padding:5px" | Default
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{context}</code>
  +
| style="padding: 5px" | 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.
  +
| style="text-align: center" | <code>Context()</code>
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{equation}</code>
  +
| style="padding: 5px" | A reference to the Formula object from which a MathObject was created (if it was the result of evaluating a Formula).
  +
| style="text-align: center" | parent Formula
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{correct_ans}</code>
  +
| style="padding: 5px" | The string to use for the correct answer when students request answers (after the due date). This is set automatically by
  +
| style="text-align: center" | <code>undef</code>
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{data}</code>
  +
| style="padding: 5px" | 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.
  +
| style="text-align: center" | object data
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{format}</code>
  +
| style="padding: 5px" | A <code>printf</code>-style string indicating how real numbers should be formatted for display. If the format ends in <code>#</code>, then trailing zeros are removed after the number is formatted. Example: <code>"%.4f"</code> would format numbers using 4-place decimals.
  +
| style="text-align: center" | <code>"%g"</code>
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{open}</code>
  +
| style="padding: 5px" | For list-type objects (e.g., Points, Vectors, Matrices, Sets), the symbol to use at the left of the object when it is displayed.
  +
| style="text-align: center" | See specific class page
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{close}</code>
  +
| style="padding: 5px" | For list-type objects (e.g., Points, Vectors, Matrices, Sets), the symbol to use at the right of the object when it is displayed.
  +
| style="text-align: center" | See specific class page
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{noinherit}</code>
  +
| style="padding: 5px" | 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 <code>text_values</code> and <code>f</code> for Formulas, and other values that are maintained automatically by the object.
  +
| style="text-align: center" | object specific
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{isValue}</code>
  +
| style="padding: 5px" | 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.
  +
| style="text-align: center" | <code>undef</code>
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{is<i>Class</i>}</code><br>E.g., <code>$mo->{isVector}</code>
  +
| style="padding: 5px" | 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 <code><i>Class</i></code> can be any of the MathObject class names, e.g, <code>$mo->{isReal}</code>.
  +
| style="text-align: center" | <code>undef</code>
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{ans_name}</code><br><code>$mo->{ans_rows}</code><br><code>$mo->{ans_cols}</code>
  +
| style="padding: 5px" | These are used by the <code>$mo->ans_array</code> method to store information about the name used for the answer array, and its size.
  +
| style="text-align: center" | <code>undef</code>
  +
  +
|- style="vertical-align: top"
  +
| style="padding: 5px; white-space: nowrap" | <code>$mo->{format_options}</code>
  +
| style="padding: 5px" | 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 <code>open</code>, <code>close</code>, and <code>sep</code>; 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.
  +
| style="text-align: center" | object specific
  +
  +
|}
   
 
<br>
 
<br>

Revision as of 08:44, 7 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;

The common properties include:

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