The body of your message seems to be missing. Can you try again?
I am not sure why the body of my question ended up being empty. I actually had to try to submit it twice as it was. Here's another go at it.
I am trying to require students to clear fractions from both sides of an equation. In order to force them to clear the fractions I have set '/' as undefined in the context of the cmp.
It works fine, although I am not satisfied with the feedback that is given when the student tries to enter a fraction in the answer blank:
"Can't use '/' in this context"
I tried to use AnswerHints to change this message as shown below, but it is not working. Any suggestions would be great!
$ans_eval3 = Formula("$rhs*$var")->cmp();
ANS($ans_eval3->withPostFilter(AnswerHints(
sub {
my ($correct, $student, $ans) = @_;
my $y = $student->value;
return (index($y,"/") == 1)
} =>["There should no longer be a fraction on this side of the equation.",replaceMessage=>1],
)));
I am trying to require students to clear fractions from both sides of an equation. In order to force them to clear the fractions I have set '/' as undefined in the context of the cmp.
It works fine, although I am not satisfied with the feedback that is given when the student tries to enter a fraction in the answer blank:
"Can't use '/' in this context"
I tried to use AnswerHints to change this message as shown below, but it is not working. Any suggestions would be great!
$ans_eval3 = Formula("$rhs*$var")->cmp();
ANS($ans_eval3->withPostFilter(AnswerHints(
sub {
my ($correct, $student, $ans) = @_;
my $y = $student->value;
return (index($y,"/") == 1)
} =>["There should no longer be a fraction on this side of the equation.",replaceMessage=>1],
)));
The AnswerHints post-filter needs to compare the student answer to the various templates that you provide. In your case, it needs to pass it to your answer checker. To do this, it must have a MathObject representing the student answer. But since there is a syntax error in the student's answer, no MathObject can be created for it, so there is no student answer to pass to your subroutine. Because of this,
AnswerHints()
can't process the answer when there is a syntax error, and so your routine is never being called.
(Even if it were, however, $student->value
isn't want you would want to be checking, but rather the original student input, $ans->{student_ans}
or perhaps the string version of the parsed student formula, $ans->{student_formula}
.)
So you would need to write a custom post-filter rather than use AnswerHints()
if you wanted to go this route.
Alternatively (and more easily), you can use the Context's error message remapping facility to replace the error message with one that you like better. You didn't say whether you used remove()
or undefine()
to delete the division symbols, but I recommend undefine()
(the message differs, for one thing). Then you could do:
Context("Numeric"); Context()->operators->undefine("/","/ "," /"); Context()->{error}{msg}{"Can't use '/' in this context"} = "There should no longer be a fraction on this side of the equation";Note that you need to remove all three operators (long story) or students will still be able to type
1 / 3
to form a fraction.
Thanks, Davide!
This worked perfectly!
Paul