Generic Answer Checker

(Based on David Cervone's vector_cmp. See doc/parser/extensions/8-answer.pg under the webwork2 directory.) Place in macros directory and load this file (Generic.pl) using the loadMacros command. (To just copy it into a pg file, replace occurences of "\&" by "~~&".)

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.

####################Example:########################## DOCUMENT(); # This should be the first executable line in the problem.

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

TEXT(&beginproblem);

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

#Easy to get by guessing!

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(); # This should be the last executable line in the problem.

####################End of Example########################