Hi,

I am writing some problems to check R commands which have characters like ~ , { and } required in the commands. I've added an operator that seems to work for checking commands with the ~ symbol, but they don't show up in the "Correct" box or the "Answer Preview" box when the answer is submitted. I have two situations:

1) The answer is checked as a string:

$ans_a1 = String(qq/hypotenuse=function($v1,$v2){sqrt($v1^2+$v2^2)}/);

hypotenuse=function(p,q)sqrt(p 2 +q 2 ) hypotenuse=function(p,q)sqrt(p 2 +q 2 ) hypotenuse=function(p,q)sqrt(p 2 +q 2 ) Correct and Answer Preview:

hypotenuse=function($v1,$v2)sqrt($v1^2+$v2^2)

I'll like to be able to check the function part as a function like I managed to do in the next part, but I couldn't see an easy way to do it without doing perl commands to strip off the function part. In the next case, the function was easier to get to:

2) The function part of the command is check as a Formula object. I wrote a macro that seems to work with the ~ symbol, but I couldn't figure out how to get it to show up in "Entered" and "Correct" boxes. I put a hyphen in for the symbol, but I'd like the tilde to show up.

Here is an example of the list I want to check:

300-5*temp ~ temp, temp=range(0,80), add=TRUE

As expected since I defined the operator this way, here is what shows up in the "Entered" and "Correct" boxes:

300-5*temp - temp, temp=range(0,80), add=TRUE

Here is the code from the problem:

$ans_2 = List(Compute("-5*temp+300~temp"), String("temp=range(0,80)"), String("add=TRUE"));

Here's the macro:

Context("Numeric");

Context()->operators->add(

'~' => {precedence => .5,

associativity => 'left',

type => 'bin',

TeX => '\sim ',

string => ' - ', # output string

class => 'Parser::BOP::comma'},

);

If I change to (string => '~') I get this error message:

### Warning messages

`Error in Translator.pm::process_answers: Answer AnSwEr0002: |-5*temp+300~temp, temp=range(0,80), add=TRUE|`

`syntax error at line 6 of (eval 25043), near ") ~"`

at line 565 of [PG]/lib/AnswerHash.pm

Died within AnswerEvaluator::evaluate called at line 1 of (eval 25030)`Error in Translator.pm::process_answers: Answer AnSwEr0002:`

`Answer evaluators must return a hash or an AnswerHash type, not type || at /opt/webwork/pg/lib/WeBWorK/PG/Translator.pm line 1232`

`Use of uninitialized value in addition (+) at (eval 24960) line 1708.`

`Use of uninitialized value $answerScore in numeric ge (>=) at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 263.`

`Use of uninitialized value $studentAnswer in pattern match (m//) at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 264.`

`Use of uninitialized value $answerScore in numeric ge (>=) at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 264.`

`Use of uninitialized value $answerScore in numeric ge (>=) at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 265.`

`Use of uninitialized value $answerScore in numeric gt (>) at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 265.`

`Use of uninitialized value $answerScore in numeric gt (>) at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 268.`

`Use of uninitialized value $answerScore in numeric eq (==) at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 270.`

`Use of uninitialized value $answerScore in numeric lt (<) at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 271.`

`Use of uninitialized value $studentAnswer in concatenation (.) or string at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 281.`

`Use of uninitialized value $correctAnswer in concatenation (.) or string at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 285.`

`Any help would be appreciated --rac`