PREP 2014 Question Authoring - Archived

removing multiple variables - context vector

Re: removing multiple variables - context vector

by Davide Cervone -
Number of replies: 0
One way to remove the variables from the context is
    Context()->variables->remove('x','y','z');
Another would be
    Context()->variables->clear();
But if you are adding new variables, the easier is to use are() rather than add(), which first removes all the existing variables and adds the new ones. So replace
    Context()->variables->remove(x); # only variables should be n 
    Context()->variables->add(n=> 'Real');  
    # how to remove y and z from Vector context?
with
    Context()->variables->are(n => 'Real');
There are several other things you probably want to change as well. First, you probably want to disable a coupe of reduction rules that reorder or regroup the terms of your expressions. You can use
    Context()->noreduce("(-x)+y","(-x)-y");
to do that. This should keep your terms in the same order you gave them originally.

Next, it looks like you have used a pretty old problem as a starting point, so have some old-style code that should be updated.

Change

    TEXT(&beginproblem);
to
    TEXT(beginproblem());
Change
    TEXT(EV2(<<EOT));
    ...
    EOT
to
   BEGIN_TEXT
   ...
   END_TEXT
and
    SOLUTION(EV3(<<'END_SOLUTION'));
to
   BEGIN_SOLUTION
and that will being you more up to date.

Davide