WeBWorK Main Forum

Malformed student formula answers lead to syntax error messages. How avoid?

Malformed student formula answers lead to syntax error messages. How avoid?

by Christian Seberino -
Number of replies: 3
When a student answers with an incorrectly formed formula, it will confuse Webwork. This leads to syntax error messages that give the student the impression Webwork is broken.

Here is an example....

The question below expects an expression. If the student erroneously
enters 3x/5 . Webwork prints the following syntax error....

  • Scalar found where operator expected at line 6 of (eval 8608), near "3 $x"
  • (Missing operator before $x?)

If a right answer is entered there is no syntax error.

How "hide" these error messages from student when THEY enter something goofy?



######################################################################

Context()->flags->set(tolerance => 0.1);

$ans = 2;

BEGIN_PGML
What is the derivative of [`-2/x`]?

[____________]{Formula("2/x^2")}
END_PGML

######################################################################
In reply to Christian Seberino

Re: Malformed student formula answers lead to syntax error messages. How avoid?

by Jason Aubrey -
Hi,

It is a strange error message, but for me it goes away when I add

Context("Numeric");

before your line which sets the tolerance.  

In general, I think you should always declare a specific context.  If I recall correctly, Numeric is the default context and MathObjects will give you that context if you don't declare one, but maybe this doesn't quite work with PGML. In any case it's best to specifically declare a context.

Jason
In reply to Jason Aubrey

Re: Malformed student formula answers lead to syntax error messages. How avoid?

by Davide Cervone -
It turns out that loading PGML.pl changes the Context, so you don't get the usual default context. (It is actually because PGML.pl loads contextTypeset.pl, and it is the one that messes up the default Context).

So for now you really must set a Context explicitly when you are using PGML.pl.

Davide