## WeBWorK Problems

### Re: Strings and Formulas -- mixing contexts?

by Davide Cervone -
Number of replies: 0
You do this by using two contexts. Since a MathObject remembers what context it was in when it was created, you can have object that are in two separate contexts (for exactly this type of situation).

Here is an example of how to do it:

   loadMacros("contextString.pl");

Context("Numeric");

$critpts = Compute("-2.7, 1.5, 3.53"); Context("String")->strings->add("+"=>{}, "-"=>{}, "0"=>{}); # define the allowed strings Context()->operators->redefine(",", from=>"Numeric"); # allow lists$signs = Compute("+,-,+,-");

BEGIN_TEXT
The critical points are: \{ans_rule(20)\}$BR The signs of the intervals between them are \{ans_rule(20)\} END_TEXT ANS($critpts->cmp(showHints=>1, showLengthHints=>1));
ANS(\$signs->cmp(ordered=>1, entry_type=>"a sign"));


Hope that does it.

Davide