WeBWorK Problems

answers that are Sets and a custom checker issue

Re: answers that are Sets and a custom checker issue

by Davide Cervone -
Number of replies: 0
The reason for your troubles is that a Set is actually a special kind of List, and so the answer checker in use is actually the list answer checker. The list answer checker calls your checker on each entry in the list, not on the list as a whole. That is probably why you needed the extra Set() commands (and that might have been a red flag that something was not quite as expected).

Rather than using checker, you should use list_checker so that you replace the complete list checker rather than the individual entry checker. In that case, $correct and $student are array references rather than MathObjects, and they point to arrays containing the elements of the lists (in this case, the elements in the set). So you do have to put them back into sets.

Here is an example:

    ANS($ans->cmp( list_checker=>sub{
      my ($correct, $student, $ansHash ) = @_;
      $correct = Set(@{$correct});
      $student = Set(@{$student});
      return ($correct->isSubsetOf($student) && $student->isSubsetOf($together) ? $student->length : 0);
Note that the list_checker returns the number of correct entries in the student answer, so that is why we use $student->length as the return value when the answer is correct.

I know it is too late for your question, but I hope this helps someone in the future.