List (MathObject Class)

From WeBWorK
Jump to: navigation, search

Contents

List Class

The List class implements arbitrary lists of other MathObjects. There is no restriction on what can be placed in a list, including other lists, other than what can be specified in the Context. For example, 1,<2,3>,5-2i,DNE is a valid List. Lists can have repeated items, as in 1,1,0,3,0,1. Lists can be enclosed in delimiters, e.g., (1,DNE), and you can have lists of lists, as in (1,increases),(3.5,decreases). If you include delimiters in a list, then students must include them as well; if you leave them off, students must also leave them off in their answers. The empty list is represented by (), though you may prefer to have student enter a value like NONE instead. Lists can be created in all the main Contexts.

The answer checker for lists allows you to specify if the order of the list matters or not, and students can enter their answers in any order by default. Lists are useful when you don't want to give away the number of answers a student may have to come up with, for example, or when you don't want to have to worry about the order of the answers. There are flags for the answer checker that you can use to change how students must enter delimiters.


Construction

Lists are created via the List() function, or by Compute(). Lists can be combined via addition or by the dot operator; these both concatenate two lists. For example:

   $L = List(1,3+i,"DNE",Vector(3,2,1));
   $L = List([1,3+i,"DNE",Vector(3,2,1)]);
   $L = List("1,3+i,DNE,<3,2,1>");        # provided i and Vectors are in the context
   $L = Compute("1,3+i,DNE,<3,2,1>");     # same caveat
   
   $L1 = List(1,2,3);  $L2 = List(4,5,6);
   $L3 = $L1 + $L2;                       # same as List(1,2,3,4,5,6)
   $L3 = $L1 . $L2;                       # same as above

If you create a list via the List() constructor that is passed a list of items rather than a string (as in the first two examples above), then this assumes no delimiters are needed. The third and fourth examples explicitly indicate that no delimiters are needed.


Answer Checker

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

   ANS(List("2,pi,sqrt(2)")->cmp);

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

Option Description Default
showHints => 1 or 0 Do/don't show messages about which entries are incorrect. $showPartialCorrectAnswers
showLengthHints => 1 or 0 Do/don't show messages about having the correct number of entries (only shown when all the student answers are correct but there are more needed, or all the correct answsers are among the ones given, but some extras were given). $showPartialCorrectAnswers
showParenHints => 1 or 0 Do/don't show messages about having the correct type of delimiters, or missing delimiters. $showPartialCorrectAnswers
partialCredit => 1 or 0 Do/don't give partial credit for when some answers are right, but not all. $showPartialCorrectAnswers
ordered => 1 or 0 Give credit only if the student answers are in the same order as the professor's answers. 0
entry_type => "a (name)" The string to use in error messages that identifies the type of elements that make up the list. determined from entries
list_type => "a (name)" The string to use in error messages that identifies the list itself. determined from list
extra => $object A MathObject to use for comparison to student-provided entries that do not match any of the correct answers in the list. Use this in particular when the correct answer is a list of a single String (like NONE), and the expected type of elements in the list are complicated and need special syntax checking (e.g., for size of Vectors). determined from entries
typeMatch => $object Specifies the type of object that the student should be allowed to enter in the list (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"). determined from entries
requireParenMatch => 1 or 0 Do/don't require the parentheses in the student's answer to match those in the professor's answer exactly. 1
removeParens => 1 or 0 Do/don't remove the parentheses from the professor's list as part of the correct answer string. This is so that if you use List() to create the list (which doesn't allow you to control the parens directly), you can still get a list with no parentheses. 1
implicitList => 1 or 0 Force/don't force single entry answers to be lists (even if they are already lists). This way, if you are asking for a list of lists, and the student enters a single list, it will be turned into a list of a single list, and will be checked properly against the correct answer. 1


Methods

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


Properties

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

Property Description Default
$r->{open} The symbol to use for the open parenthesis undef
$r->{close} The symbol to use for the close parenthesis undef



follow us