WeBWorK Main Forum

How do multiple questions/answers in a PGML problem with multiple Contexts?

Re: How do multiple questions/answers in a PGML problem with multiple Contexts?

by Davide Cervone -
Number of replies: 0
Another slight clarification: the command
    Context("Context1");
    $MathObject = Compute("...");
    Context("Context2");
    $MathObject1 = Compute($MathObject1);
doesn't really recompute $MathObject1, it just switches what context it is associated with (but doesn't re-parse the object using the new rules). So, for example,
    Context("Vector");
    $f = Compute("<x,x+1>");
    Context("Numeric");
    $f = Compute($f);
doesn't cause an error, it simply forces the formula for $f to think it is from the Numeric context. If
    ANS($f->cmp);
were used, the student would have no way to enter the correct answer, since the vector could not be entered in Numeric context.

On the other hand,

    Context("Vector");
    $f = Compute("<x,x+1>");
    Context("Numeric");
    $f = Compute("$f");
would cause an error, because here "$f" means $f is first stringified, and then Compute() re-parses the string, leading to an error, since < is not defined in Numeric context.

This is one of the places where the difference between $f and "$f" is crucial.

Davide