WeBWorK Problems

Compile errors that seem to be because of the use of y as a variable

Compile errors that seem to be because of the use of y as a variable

by Murphy Waggoner -
Number of replies: 2
I struggled to find the source of the error in this code.  It turns out that when I change the y highlighted below to b this worked fine.  But with the y in I have gotten a variety of errors depending on what I had commented out.  The error messages for this particular version is

 Compilation errorMissing right curly or square bracket at (eval 2449) line 44, at end of line

WeBWorK Warnings

WeBWorK has encountered warnings while processing your request. If this occured when viewing a problem, it was likely caused by an error or ambiguity in that problem. Otherwise, it may indicate a problem with the WeBWorK system itself. If you are a student, report these warnings to your professor to have them corrected. If you are a professor, please consult the warning output below for more information.

Warning messages

  • Scalar found where operator expected at line 33 of (eval 2426), near "$BR"
  • (Might be a runaway multi-line ,, string starting on line 23)
  • (Missing operator before
  • $BR?)
  • Backslash found where operator expected at line 34 of (eval 2426), near "$BR
  • \"
  • (Missing semicolon on previous line?)
  • Backslash found where operator expected at line 34 of (eval 2426), near ") \"
  • (Missing operator before \?)
  • Backslash found where operator expected at line 34 of (eval 2426), near ")\"
  • (Missing operator before \?)
  • Processing of this PG problem was not completed. Probably because of a syntax error.
  • The translator died prematurely and no PG warning messages were transmitted. at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 700.

DOCUMENT();        # This should be the first executable line in the problem.

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGcourse.pl",
);

TEXT(beginproblem());
$showPartialCorrectAnswers = 1;

Context('Matrix');
Context()->variables->add(a => "Real");
Context()->variables->add(y => "Real");
$a = Real(non_zero_random(-9,9,1));
$b = Real(non_zero_random(-9,9,1));

$mm = Compute("1 - $b");
$nn = Compute("$b * (1 - $b)/$a");

$A = Matrix([
[ a, $a],
[ y, $b],
]);


Context()->texStrings;
BEGIN_TEXT
For the 2 x 2 matrix \($A\)
determine the values of \(a\) and \(b\) for which \(A^2=A\)
$BR$BR
\(a=\) \{ans_rule(10)\}, 
$BR
\(b=\) \{ans_rule(10)\}. 

END_TEXT
Context()->normalStrings;


ANS( $mm->cmp );
ANS( $nn->cmp );



ENDDOCUMENT();
In reply to Murphy Waggoner

Re: Compile errors that seem to be because of the use of y as a variable

by Davide Cervone -
The problem is that you have left out quotation marks around the variable names in the definition of your matrix. That is, you should use
$A = Matrix([
  [ "a", $a],
  [ "y", $b],
]);
Without this, Perl tries to interpret that a and y as Perl expressions. The a (and your b) have no particular meaning to Perl, so they become string literals automatically. But y is a transliteration operator (for converting one set of characters to another), and the character that follows it is used as the delimiters for the lists of character to be translated. So y, means that everything up to the next comma is the set of character that are to be translated, and up to the next comma is the set of characters to translate to. The error message is complaining about the fact that there is no third comma to close the second list.

In any case, putting quotation marks around the expressions that are to be parsed should take care of it for you.

In reply to Davide Cervone

Re: Compile errors that seem to be because of the use of y as a variable

by Murphy Waggoner -
Thanks, Davide.  I seem to be struggling to write even the simplest question lately.  It is probably because I am trying to use the Matrix context and am not quite familiar with it.  I tried the following for the problem above and it wouldn't work.  At that time I didn't think of putting the " " around just the individual variable expressions.

$A = Matrix("[
  [ a, $a],
  [ y, $b],
]");

I had one today where the expressions were more complex than above.  My final (working)
version looked  something like this.  So, I think I've learned my lesson.   Finger's crossed.

$A = Matrix("[
  [ Formula("$a a^2 - 2"), $a],
  [ Formula("$b a b + b^2"), $b],
]");