NAME

Generic.pl - Provide some generic answer checkers.

DESCRIPTION

This macro provides a set of functions that provide a generic answer checker.

Usage:

ANS(  generic_cmp(<prof_answer>, <optional and mandatory arguments>) );

where <prof_answer> is a parser object or syntactically correct string for a parser object.

Mandatory arguments:

type => <type>

where <type> is a recognized parser type (e.g., Number, Point, Vector, Matrix, etc.)

checker => <checker>

where <checker> is a reference to a subroutine that will be passed (in order) the parsed (and, if possible, evaluated) student answer, the parsed professor's answer, and a reference to the answer hash. (The last is so that it can return error messages if desired.) In simple evaluators, the last two are typically not used.

Optional arguments:

correct_ans => <answer_string>

where <answer_string> is a string that will show up as the correct answer when solutions are available.

variables_allowed => 0 or 1

(default 0 (false). Determines whether student's answer is allowed to contain variables. In this case the checker must take care of evaluating it.)

length => n

where n is the number of elements in an expected answer of type list, vector, or points. Returns error message to student if answer of wrong length is entered.

SYNOPSIS

DOCUMENT();

loadMacros("PG.pl", "PGbasicmacros.pl", "PGanswermacros.pl", "Parser.pl", "Generic.pl");

Context("Vector");
$A=Vector(1,2,1);
$B=Vector(1,3,1);
$C=Vector(1,4,1);

BEGIN_TEXT
Show that the vectors \(\{$A->TeX\}, \{$B->TeX\}, \{$C->TeX\}\) do
not span \(R^3\) by giving a vector not in their span:
\{ans_rule()\}
END_TEXT

sub check {
  my $stu=shift;
  $x1=$stu->extract(1); $x3=$stu->extract(3);
  $x1 != $x3; #any vectors with different 1st and 3rd coordinates
}

ANS(generic_cmp("23",type => 'Vector', length => 3, checker => ~~&check));

ENDDOCUMENT();

FUNCTIONS

generic_cmp

generic_cmp_check