WeBWorK Main Forum

Error with adding string to context after upgrade to WW 2.16

Re: Error with adding string to context after upgrade to WW 2.16

by Davide Cervone -
Number of replies: 0
Is there anything that changed with the upgrade that would cause the error with the PG code?

Yes. The Context now checks that an alias points to an exiting entry in the context and provides a warning if not (the warning you are seeing). Note that the R constant is only defined in the Interval context (and related ones), but the alias to it is being made in the LImitedNumeric context. It does not exist in that context, which leads to the error you are seeing. And even if you were in the Interval context, this still would not work, since the R in that context is a constant (tied to the interval (-infinity, infinity)), not a string, so your problem would still generate this error.

In the LimitedNumeric context, you could do

Context()->strings->add("All Real Numbers" => {}, R => {alias => "All Real Numbers"});
which would resolve the problem, and would show R as All Real Numbers in student and correct answers.

This is what is done for the Inequalities context for answers (c) and (d). Unfortunately, it is not correct there, since R is already defined as a constant, so you are generating a second definition for the string (it does override the earlier definition in this case). But you don't really want R to be a string in this case, as R can be used in expressions like R - {0}, which will cause an error if you redefine R in this way.

Instead, you should make All Real Numbers be a *constant* not a string. Unfortunately, constant don't usually allow spaces in their names, so you would need to modify the name pattern first:

Context("Inequalities");
Context()->constants->{namePattern} = qr/.+/;   # allow anything as a name
Context()->constants->add("All Real Numbers" => {alias => "R"});

Note that the problem says you are to use interval notation (like [1,infinity)), but the problem's answer hints filters require the answer to use inequalities, not intervals, which could cause confusion. Also, the context you are using allows interval notation to be entered, but then marks it incorrect since it is not an inequality. You might consider using the Inequalities-Only context instead, which will give a better error message when intervals are used. Of course, you should reword the problem to indicate the inequalities are to be used, not intervals.

The Inequalities-Only context does not have R defined, so you would need to use

Context()->strings->add("All Real Numbers" => {}, R => {alias => "All Real Numbers"});
again in this case.