From: dpvc v. a. <we...@ma...> - 2005-09-06 21:01:23
|
Log Message: ----------- Movified the copying of functions from Complex1:: into main:: to avoid conflicts with the PGcommonFunctions.pl versions (these errors were trapped, but still show up in the error log unnecessarily). Also commented out some code that was not doing anything other than producing error messages in the error log. (It was left over from a syntax check on the professor's answer, but the actual check was removed, leaving a portion that tries to process the answer, but usually fails (because things like "1+4i" need to be converted to "1+4*i" before they can be used in PG_answer_eval, but that was not being done). Because of this, it is not possible currently to do cplx_cmp("1+4i"), and instead you must to cplx_cmp(new Complex(1,4)). To fix this, you would need to call check_syntax (and the other filters that are called on the student's answer) before calling PG_answer_eval. Of course, you should only do this when the professor's answer isn't already a Complex object. I am going to work on a Legacy module like the ones for num_cmp and fun_cmp to replace cplx_cmp, which should avoid these problems and make the changes suggested above unnecessary. Modified Files: -------------- pg/macros: PGcommonFunctions.pl PGcomplexmacros.pl Revision Data ------------- Index: PGcommonFunctions.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/PGcommonFunctions.pl,v retrieving revision 1.6 retrieving revision 1.7 diff -Lmacros/PGcommonFunctions.pl -Lmacros/PGcommonFunctions.pl -u -r1.6 -r1.7 --- macros/PGcommonFunctions.pl +++ macros/PGcommonFunctions.pl @@ -27,6 +27,7 @@ return Parser::Function->call($fn,@_) if Parser::Context->current->{functions}{$fn}; } + return &{$CommonFunction::function{$fn}}(@_) if $CommonFunction::function{$fn}; return $self->$fn(@_); } Index: PGcomplexmacros.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/PGcomplexmacros.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -Lmacros/PGcomplexmacros.pl -Lmacros/PGcomplexmacros.pl -u -r1.9 -r1.10 --- macros/PGcomplexmacros.pl +++ macros/PGcomplexmacros.pl @@ -35,17 +35,20 @@ foreach my $f (@Complex1::EXPORT) { # #PG_restricted_eval("\*$f = \*Complex1::$f"); # this is too clever -- # the original subroutines are destroyed - next if $f eq 'sqrt'; #exporting the square root caused conflicts with the standard version - # You can still use Complex1::sqrt to take square root of complex numbers - next if $f eq 'log'; #exporting loq caused conflicts with the standard version - # You can still use Complex1::log to take square root of complex numbers - - my $string = qq{ - sub main::$f { - &Complex1::$f; - } - }; +# next if $f eq 'sqrt'; #exporting the square root caused conflicts with the standard version +# # You can still use Complex1::sqrt to take square root of complex numbers +# next if $f eq 'log'; #exporting loq caused conflicts with the standard version +# # You can still use Complex1::log to take square root of complex numbers + + next if $f eq 'i' || $f eq 'pi'; + my $code = PG_restricted_eval("\\&CommonFunction::$f"); + if (defined($code) && defined(&{$code})) { + $CommonFunction::function{$f} = "Complex1::$f"; # PGcommonMacros now takes care of this. + } else { + my $string = qq{sub main::$f {&Complex1::$f}}; PG_restricted_eval($string); + } + } @@ -137,15 +140,28 @@ $correct_num_answer = math_constants($correct_num_answer); my $PGanswerMessage = ''; - - my ($inVal,$correctVal,$PG_eval_errors,$PG_full_error_report); - - if (defined($correct_num_answer) && $correct_num_answer =~ /\S/ && $corrAnswerIsString == 0 ) { - ($correctVal, $PG_eval_errors,$PG_full_error_report) = PG_answer_eval($correct_num_answer); - } else { # case of a string answer - $PG_eval_errors = ' '; - $correctVal = $correctAnswer; - } + +# +# The following lines don't have any effect (other than to take time and produce errors +# in the error log). The $correctVal is replaced on the line following the comments, +# and the error values are never used. It LOOKS like this was supposed to perform a +# check on the professor's answer, but that is not occurring. (There used to be some +# error checking, but that was removed in version 1.9 and it had been commented out +# prior to that because it was always producing errors. This is because $correct_num_answer +# usually is somethine like "1+4i", which will produce a "missing operation before 'i'" +# error, and "1-i" wil produce an "amiguous use of '-i' resolved as '-&i'" message. +# You probably need a call to check_syntax and the other filters that are used on +# the student answer first. (Unless the item is already a reference to a Complex, +# in which canse you should just accept it.) +# +# my ($inVal,$correctVal,$PG_eval_errors,$PG_full_error_report); + my $correctVal; +# if (defined($correct_num_answer) && $correct_num_answer =~ /\S/ && $corrAnswerIsString == 0 ) { +# ($correctVal, $PG_eval_errors,$PG_full_error_report) = PG_answer_eval($correct_num_answer); +# } else { # case of a string answer +# $PG_eval_errors = ' '; +# $correctVal = $correctAnswer; +# } ######################################################################## $correctVal = $correct_num_answer; |