1  sub _answerHints_init {} 
1  sub _answerHints_init {} 
2  
2  
3  =head1 AnswerHints() 
3  =head1 AnswerHints() 
4  
4  
5  # This is an answerchecker postfilter that allows you to produce 
5  This is an answerchecker postfilter that allows you to produce 
6  # additional error messages for incorrect answers. You can trigger 
6  additional error messages for incorrect answers. You can trigger 
7  # a message for a single answer, a collection of answers, or via a 
7  a message for a single answer, a collection of answers, or via a 
8  # subroutine that determines the condition for the message. 
8  subroutine that determines the condition for the message. 
9  # 
9  
10  # Note that this filter only works for MathObjects answer checkers. 
10  Note that this filter only works for MathObjects answer checkers. 
11  # 
11  
12  # The answer hints are given as a pair using => with the righthand 
12  The answer hints are given as a pair using => with the righthand 
13  # side being the answer message and the lefthand side being one of 
13  side being the answer message and the lefthand side being one of 
14  # three possibilities: 1) the value that triggers the message, 
14  three possibilities: 1) the value that triggers the message, 
15  # 2) a reference to an array of values that trigger the message, or 
15  2) a reference to an array of values that trigger the message, or 
16  # 3) a code reference to a subtroutine that accepts tthe correct 
16  3) a code reference to a subtroutine that accepts tthe correct 
17  # answer, the student's answer, and the answer hash, and returns 
17  answer, the student's answer, and the answer hash, and returns 
18  # 1 or 0 depending on whether the message should or should not be 
18  1 or 0 depending on whether the message should or should not be 
19  # displayed. (See the examples below.) 
19  displayed. (See the examples below.) 
20  # 
20  
21  # The righthand side can be either the message string itself, or 
21  The righthand side can be either the message string itself, or 
22  # a referrence to an array where the first element is the message 
22  a referrence to an array where the first element is the message 
23  # string, and the remaining elements are namevalue pairs that 
23  string, and the remaining elements are namevalue pairs that 
24  # set options for the message. These can include: 
24  set options for the message. These can include: 
25  # 
25  
26  # checkCorrect => 0 or 1 1 means check for messages even 
26  =over 
27  # if the answer is correct. 
27  
28  # Default: 0 
28  =item C<S<< checkCorrect => 0 or 1 >>> 
29  # 
29  
30  # replaceMessage => 0 or 1 1 means it's OK to repalce any 
30  1 means check for messages even 
31  # message that is already in place 
31  if the answer is correct. 
32  # in the answer hash. 
32  Default: 0 
33  # Default: 0 
33  
34  # 
34  =item C<S<< replaceMessage => 0 or 1 >>> 
35  # checkTypes => 0 or 1 1 means only perform the test 
35  
36  # if the student answer is the 
36  1 means it's OK to repalce any 
37  # same type as the correct one. 
37  message that is already in place 
38  # Default: 1 
38  in the answer hash. 
39  # 
39  Default: 0 
40  # score => number Specifies the score to use if 
40  
41  # the message is triggered (so that 
41  =item C<S<< checkTypes => 0 or 1 >>> 
42  # partial credit can be given). 
42  
43  # Default: keep original score 
43  1 means only perform the test 
44  # 
44  if the student answer is the 
45  # cmp_options => [...] provides options for the cmp routine 
45  same type as the correct one. 
46  # used to check if the student answer 
46  Default: 1 
47  # matches these answers. 
47  
48  # Default: [] 
48  =item C<S<< score => number >>> 
49  # 
49  


50  Specifies the score to use if 


51  the message is triggered (so that 


52  partial credit can be given). 


53  Default: keep original score 


54  


55  =item C<S<< cmp_options => [...] >>> 


56  


57  provides options for the cmp routine 


58  used to check if the student answer 


59  matches these answers. 


60  Default: [] 


61  


62  =back 


63  
50  # If more than one message matches the student's answer, the first 
64  If more than one message matches the student's answer, the first 
51  # one in the list is used. 
65  one in the list is used. 
52  # 
66  
53  # Example: 
67  Example: 
54  # 
68  
55  # ANS(Vector(1,2,3)>cmp(showCoordinateHints=>0)>withPostFilter(AnswerHints( 
69  ANS(Vector(1,2,3)>cmp(showCoordinateHints=>0)>withPostFilter(AnswerHints( 
56  # Vector(0,0,0) => "The zero vector is not a valid solution", 
70  Vector(0,0,0) => "The zero vector is not a valid solution", 
57  # "<1,2,3>" => "Try the opposite direction", 
71  "<1,2,3>" => "Try the opposite direction", 
58  # "<1,2,3>" => "Well done!", 
72  "<1,2,3>" => "Well done!", 
59  # ["<1,1,1>","<2,2,2>","<3,3,3>"] => "Don't just guess!", 
73  ["<1,1,1>","<2,2,2>","<3,3,3>"] => "Don't just guess!", 
60  # sub { 
74  sub { 
61  # my ($correct,$student,$ans) = @_; 
75  my ($correct,$student,$ans) = @_; 
62  # return $correct . $student == 0; 
76  return $correct . $student == 0; 
63  # } => "Your answer is perpendicular to the correct one", 
77  } => "Your answer is perpendicular to the correct one", 
64  # Vector(1,2,3) => [ 
78  Vector(1,2,3) => [ 
65  # "You have the right direction, but not length", 
79  "You have the right direction, but not length", 
66  # cmp_options => [parallel=>1], 
80  cmp_options => [parallel=>1], 
67  # ], 
81  ], 
68  # 0 => ["Careful, your answer should be a vector!", checkTypes => 0, replaceMessage => 1], 
82  0 => ["Careful, your answer should be a vector!", checkTypes => 0, replaceMessage => 1], 
69  # sub { 
83  sub { 
70  # my ($correct,$student,$ans) = @_; 
84  my ($correct,$student,$ans) = @_; 
71  # return norm($correct$student) < .1; 
85  return norm($correct$student) < .1; 
72  # } => ["Close! Keep trying.", score => .25], 
86  } => ["Close! Keep trying.", score => .25], 
73  # ))); 
87  ))); 
74  # 


75  
88  
76  =cut 
89  =cut 
77  
90  
78  sub AnswerHints { 
91  sub AnswerHints { 
79  return (sub { 
92  return (sub { 