[system] / trunk / pg / macros / PGanswermacros.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/PGanswermacros.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2060 Revision 2061
131 $functULimitDefault , 131 $functULimitDefault ,
132 $functMaxConstantOfIntegration , 132 $functMaxConstantOfIntegration ,
133 $CA , 133 $CA ,
134 $rh_envir , 134 $rh_envir ,
135 $useBaseTenLog , 135 $useBaseTenLog ,
136 $inputs_ref ,
136 $QUESTIONNAIRE_ANSWERS , 137 $QUESTIONNAIRE_ANSWERS ,
138
137); 139);
138 140
139 141
140 142
141 143
160 $functLLimitDefault = main::PG_restricted_eval(q!$main::functLLimitDefault!); 162 $functLLimitDefault = main::PG_restricted_eval(q!$main::functLLimitDefault!);
161 $functULimitDefault = main::PG_restricted_eval(q!$main::functULimitDefault!); 163 $functULimitDefault = main::PG_restricted_eval(q!$main::functULimitDefault!);
162 $functMaxConstantOfIntegration = main::PG_restricted_eval(q!$main::functMaxConstantOfIntegration!); 164 $functMaxConstantOfIntegration = main::PG_restricted_eval(q!$main::functMaxConstantOfIntegration!);
163 $rh_envir = main::PG_restricted_eval(q!\%main::envir!); 165 $rh_envir = main::PG_restricted_eval(q!\%main::envir!);
164 $useBaseTenLog = main::PG_restricted_eval(q!\%main::useBaseTenLog!); 166 $useBaseTenLog = main::PG_restricted_eval(q!\%main::useBaseTenLog!);
167 $inputs_ref = main::PG_restricted_eval(q!$main::inputs_ref!);
165 $QUESTIONNAIRE_ANSWERS = ''; 168 $QUESTIONNAIRE_ANSWERS = '';
166} 169}
167 170
168 171
169 172
1343 1346
1344=cut 1347=cut
1345 1348
1346sub fun_cmp { 1349sub fun_cmp {
1347 my $correctAnswer = shift @_; 1350 my $correctAnswer = shift @_;
1348 my %opt = @_; 1351 my %opt = @_;
1349 1352
1350 assign_option_aliases( \%opt, 1353 assign_option_aliases( \%opt,
1351 'vars' => 'var', # set the standard option 'var' to the one specified as vars 1354 'vars' => 'var', # set the standard option 'var' to the one specified as vars
1352 'domain' => 'limits', # set the standard option 'limits' to the one specified as domain 1355 'domain' => 'limits', # set the standard option 'limits' to the one specified as domain
1353 'reltol' => 'relTol', 1356 'reltol' => 'relTol',
1728 1731
1729sub FUNCTION_CMP { 1732sub FUNCTION_CMP {
1730 my %func_params = @_; 1733 my %func_params = @_;
1731 1734
1732 my $correctEqn = $func_params{'correctEqn'}; 1735 my $correctEqn = $func_params{'correctEqn'};
1733 my $var = $func_params{'var'}; 1736 my $var = $func_params{'var'};
1734 my $ra_limits = $func_params{'limits'}; 1737 my $ra_limits = $func_params{'limits'};
1735 my $tol = $func_params{'tolerance'}; 1738 my $tol = $func_params{'tolerance'};
1736 my $tolType = $func_params{'tolType'}; 1739 my $tolType = $func_params{'tolType'};
1737 my $numPoints = $func_params{'numPoints'}; 1740 my $numPoints = $func_params{'numPoints'};
1738 my $mode = $func_params{'mode'}; 1741 my $mode = $func_params{'mode'};
1739 my $maxConstantOfIntegration = $func_params{'maxConstantOfIntegration'}; 1742 my $maxConstantOfIntegration = $func_params{'maxConstantOfIntegration'};
1740 my $zeroLevel = $func_params{'zeroLevel'}; 1743 my $zeroLevel = $func_params{'zeroLevel'};
1741 my $zeroLevelTol = $func_params{'zeroLevelTol'}; 1744 my $zeroLevelTol = $func_params{'zeroLevelTol'};
1742 my $ra_test_points = $func_params{'test_points'}; 1745 my $ra_test_points = $func_params{'test_points'};
1743 1746
1744 1747
1745 # Check that everything is defined: 1748 # Check that everything is defined:
1746 $func_params{debug} = 0 unless defined($func_params{debug}); 1749 $func_params{debug} = 0 unless defined($func_params{debug});
1747 $mode = 'std' unless defined($mode); 1750 $mode = 'std' unless defined($mode);
1828 $rh_correct_ans->input($correctEqn); 1831 $rh_correct_ans->input($correctEqn);
1829 $rh_correct_ans = check_syntax($rh_correct_ans); 1832 $rh_correct_ans = check_syntax($rh_correct_ans);
1830 warn $rh_correct_ans->{error_message} if $rh_correct_ans->{error_flag}; 1833 warn $rh_correct_ans->{error_message} if $rh_correct_ans->{error_flag};
1831 $rh_correct_ans->clear_error(); 1834 $rh_correct_ans->clear_error();
1832 $rh_correct_ans = function_from_string2($rh_correct_ans, ra_vars => [ @VARS, @PARAMS ], 1835 $rh_correct_ans = function_from_string2($rh_correct_ans, ra_vars => [ @VARS, @PARAMS ],
1833 stdout =>'rf_correct_ans', 1836 stdout => 'rf_correct_ans',
1834 debug => $func_params{debug}); 1837 debug => $func_params{debug});
1835 my $correct_eqn_sub = $rh_correct_ans->{rf_correct_ans}; 1838 my $correct_eqn_sub = $rh_correct_ans->{rf_correct_ans};
1836 warn $rh_correct_ans->{error_message} if $rh_correct_ans->{error_flag}; 1839 warn $rh_correct_ans->{error_message} if $rh_correct_ans->{error_flag};
1837 1840
1838###################################################################### 1841
1839# prepare the previous student answer and check its syntax as well
1840######################################################################
1841# FIXME We need to be able to retrieve, not the sticky answer, but the answer previous to that one
1842# in order to be able to check whether the current answer is different from the one just entered
1843# This will require additional storage provided, I believe by PGtranslator.pm
1844# OR BETTER YET perhaps we can store this in the HTML document using hidden variables.
1845# this could be a change in PGbasicmacros which printed a hidden version of the previous answer
1846# along with the blank that was modified.
1847#
1848# my $rh_prev_ans = new AnswerHash;
1849# $rh_prev_ans->input( PREVIOUS ANSWER FOR COMPARISON HERE);
1850# $rh_prev_ans = check_syntax($rh_prev_ans);
1851# warn $rh_prev_ans->{error_message} if $rh_prev_ans->{error_flag};
1852# $rh_prev_ans->clear_error();
1853# $rh_prev_ans = function_from_string2($rh_prev_ans, ra_vars => [ @VARS, @PARAMS ],
1854# stdout =>'rf_prev_ans',
1855# debug => $func_params{debug});
1856# my $prev_eqn_sub = $rh_prev_ans->{rf_prev_ans};
1857# warn $rh_prev_ans->{error_message} if $rh_prev_ans->{error_flag};
1858 1842
1859###################################################################### 1843######################################################################
1860# define the points at which the functions are to be evaluated 1844# define the points at which the functions are to be evaluated
1861###################################################################### 1845######################################################################
1862 1846
1892 rf_correct_ans => $rh_correct_ans->{rf_correct_ans}, 1876 rf_correct_ans => $rh_correct_ans->{rf_correct_ans},
1893 evaluation_points => \@evaluation_points, 1877 evaluation_points => \@evaluation_points,
1894 ra_param_vars => \@PARAMS, 1878 ra_param_vars => \@PARAMS,
1895 ra_vars => \@VARS, 1879 ra_vars => \@VARS,
1896 type => 'function', 1880 type => 'function',
1881 score => 0,
1897 ); 1882 );
1883 #########################################################
1884 # Prepare the previous answer for evaluation, discard errors
1885 #########################################################
1886 $answer_evaluator->install_pre_filter(sub { my $rh_ans = shift;
1887 $rh_ans->{_filter_name} = "fetch_previous_answer";
1888 my $prev_ans_label = "previous_".$rh_ans->{ans_label};
1889 $rh_ans->{prev_ans} =
1890 (defined( $inputs_ref->{$prev_ans_label} and $inputs_ref->{$prev_ans_label} =~/\S/) ) ?
1891 $inputs_ref->{$prev_ans_label} : undef;
1892 $rh_ans;
1893 }
1894 );
1895 $answer_evaluator->install_pre_filter(sub { my $rh_ans = shift;
1896 return $rh_ans unless defined($rh_ans->{prev_ans});
1897 check_syntax($rh_ans,
1898 stdin => 'prev_ans',
1899 stdout => 'prev_ans',
1900 error_msg_flag => 0
1901 );
1902 $rh_ans->{_filter_name} = "check_syntax_of_previous_answer";
1903 $rh_ans;
1904 }
1905 );
1906 $answer_evaluator->install_pre_filter(sub { my $rh_ans = shift;
1907 return $rh_ans unless defined($rh_ans->{prev_ans});
1908 function_from_string2($rh_ans,
1909 stdin => 'prev_ans',
1910 stdout => 'rf_prev_ans',
1911 ra_vars => \@VARS,
1912 debug=>$func_params{debug}
1913 );
1914 $rh_ans->{_filter_name} = "compile_previous_answer";
1915 $rh_ans;
1916 }
1917 );
1918 #########################################################
1919 # Prepare the current answer for evaluation
1920 #########################################################
1898 1921
1899 $answer_evaluator->install_pre_filter(\&check_syntax); 1922 $answer_evaluator->install_pre_filter(\&check_syntax);
1900 $answer_evaluator->install_pre_filter(\&function_from_string2, ra_vars => \@VARS,debug=>$func_params{debug},); # @VARS has been guaranteed to be an array, $var might be a single string. 1923 $answer_evaluator->install_pre_filter(\&function_from_string2, ra_vars => \@VARS,
1924 debug => $func_params{debug}
1925 ); # @VARS has been guaranteed to be an array, $var might be a single string.
1926 #########################################################
1927 # Compare the previous and current answer. Discard errors
1928 #########################################################
1929
1930 $answer_evaluator->install_evaluator(sub { my $rh_ans = shift;
1931 return $rh_ans unless defined($rh_ans->{rf_prev_ans});
1932 calculate_difference_vector($rh_ans,
1933 %func_params,
1934 stdin1 => 'rf_student_ans',
1935 stdin2 => 'rf_prev_ans',
1936 stdout => 'ra_diff_with_prev_ans',
1937 error_msg_flag => 0,
1938 );
1939 $rh_ans->{_filter_name} = "calculate_difference_vector_of_previous_answer";
1940 $rh_ans;
1941 }
1942 );
1943 $answer_evaluator->install_evaluator(sub { my $rh_ans = shift;
1944 return $rh_ans unless defined($rh_ans->{ra_diff_with_prev_ans});
1945 is_zero_array( $rh_ans,
1946 stdin => 'ra_diff_with_prev_ans',
1947 stdout => 'ans_equals_prev_ans'
1948 );
1949 }
1950 );
1951 #########################################################
1952 # Calculate values for approximation parameters and
1953 # compare the current answer with the correct answer. Keep errors this time.
1954 #########################################################
1955
1901 $answer_evaluator->install_pre_filter(\&best_approx_parameters, %func_params, param_vars => \@PARAMS); 1956 $answer_evaluator->install_pre_filter(\&best_approx_parameters, %func_params, param_vars => \@PARAMS);
1902 $answer_evaluator->install_evaluator(\&calculate_difference_vector, %func_params); 1957 $answer_evaluator->install_evaluator(\&calculate_difference_vector, %func_params);
1903 $answer_evaluator->install_evaluator(\&is_zero_array, tolerance => $tol ); 1958 $answer_evaluator->install_evaluator(\&is_zero_array, tolerance => $tol );
1959
1904 $answer_evaluator->install_post_filter(sub {my $rh_ans = shift; $rh_ans->clear_error('SYNTAX'); $rh_ans;} ); 1960 $answer_evaluator->install_post_filter(sub {my $rh_ans = shift; $rh_ans->clear_error('SYNTAX'); $rh_ans;} );
1905 $answer_evaluator->install_post_filter( 1961 $answer_evaluator->install_post_filter(
1906 sub {my $rh_ans = shift; 1962 sub {my $rh_ans = shift;
1907 if ($rh_ans->catch_error('EVAL') ) { 1963 if ($rh_ans->catch_error('EVAL') ) {
1908 $rh_ans->{ans_message} = $rh_ans->{error_message}; 1964 $rh_ans->{ans_message} = $rh_ans->{error_message};
1909 $rh_ans->clear_error('EVAL'); 1965 $rh_ans->clear_error('EVAL');
1966 }
1967 $rh_ans;
1968 }
1969 );
1970 $answer_evaluator->install_post_filter(
1971 sub {my $rh_ans = shift;
1972 if ( defined($rh_ans->{'ans_equals_prev_ans'}) and $rh_ans->{'ans_equals_prev_ans'} and $rh_ans->{score}==0) {
1973 $rh_ans->{ans_message} = "This answer is the same as the one you just submitted.";
1974
1910 } 1975 }
1911 $rh_ans; 1976 $rh_ans;
1912 } 1977 }
1913 ); 1978 );
1914 $answer_evaluator; 1979 $answer_evaluator;
2764 my $msg = $_[0]; 2829 my $msg = $_[0];
2765 $msg =~ s/^\[[^\]]*\][^:]*://; 2830 $msg =~ s/^\[[^\]]*\][^:]*://;
2766 $msg =~ s/Unquoted string//g; 2831 $msg =~ s/Unquoted string//g;
2767 $msg =~ s/may\s+clash.*/does not make sense here/; 2832 $msg =~ s/may\s+clash.*/does not make sense here/;
2768 $msg =~ s/\sat.*line [\d]*//g; 2833 $msg =~ s/\sat.*line [\d]*//g;
2769 $msg = 'error: '. $msg; 2834 $msg = 'Error: '. $msg;
2770 2835
2771 return $msg; 2836 return $msg;
2772} 2837}
2773 2838
2774#formats the student and correct answer as specified 2839#formats the student and correct answer as specified
2912 $PG_eval_errors = ''; 2977 $PG_eval_errors = '';
2913 } 2978 }
2914 2979
2915 if ($PG_eval_errors) { ##error message from eval or above 2980 if ($PG_eval_errors) { ##error message from eval or above
2916 $rh_ans->{ans_message} = 'There is a syntax error in your answer'; 2981 $rh_ans->{ans_message} = 'There is a syntax error in your answer';
2982 $rh_ans->{student_ans} =
2917 $rh_ans->{student_ans} = clean_up_error_msg($PG_eval_errors); 2983 clean_up_error_msg($PG_eval_errors);
2918 } else { 2984 } else {
2919 $rh_ans->{student_ans} = $inVal; 2985 $rh_ans->{student_ans} = $inVal;
2920 } 2986 }
2921 $rh_ans; 2987 $rh_ans;
2922} 2988}
2990 '_filter_name' => 'function_from_string2', 3056 '_filter_name' => 'function_from_string2',
2991 ); 3057 );
2992 # initialize 3058 # initialize
2993 $rh_ans->{_filter_name} = $options{_filter_name}; 3059 $rh_ans->{_filter_name} = $options{_filter_name};
2994 3060
2995 my $eqn = $rh_ans->{student_ans}; 3061 my $eqn = $rh_ans->{ $options{stdin} };
2996 my @VARS = @{ $options{ 'ra_vars'}}; 3062 my @VARS = @{ $options{ 'ra_vars'} };
2997 #warn "VARS = ", join("<>", @VARS) if defined($options{debug}) and $options{debug} ==1; 3063 #warn "VARS = ", join("<>", @VARS) if defined($options{debug}) and $options{debug} ==1;
2998 my $originalEqn = $eqn; 3064 my $originalEqn = $eqn;
2999 $eqn = &math_constants($eqn); 3065 $eqn = &math_constants($eqn);
3000 for( my $i = 0; $i < @VARS; $i++ ) { 3066 for( my $i = 0; $i < @VARS; $i++ ) {
3001 # This next line is a hack required for 5.6.0 -- it doesn't appear to be needed in 5.6.1 3067 # This next line is a hack required for 5.6.0 -- it doesn't appear to be needed in 5.6.1
3002 my ($temp,$er1,$er2) = PG_restricted_eval('"'. $VARS[$i] . '"'); 3068 my ($temp,$er1,$er2) = PG_restricted_eval('"'. $VARS[$i] . '"');
3003 #$eqn =~ s/\b$VARS[$i]\b/\$VARS[$i]/g; 3069 #$eqn =~ s/\b$VARS[$i]\b/\$VARS[$i]/g;
3004 $eqn =~ s/\b$temp\b/\$VARS[$i]/g; 3070 $eqn =~ s/\b$temp\b/\$VARS[$i]/g;
3067 my $rh_ans = shift; 3133 my $rh_ans = shift;
3068 my %options = @_; 3134 my %options = @_;
3069 set_default_options( \%options, 3135 set_default_options( \%options,
3070 '_filter_name' => 'is_zero_array', 3136 '_filter_name' => 'is_zero_array',
3071 'tolerance' => 0.000001, 3137 'tolerance' => 0.000001,
3138 'stdin' => 'ra_differences',
3139 'stdout' => 'score',
3072 ); 3140 );
3073 #intialize 3141 #intialize
3074 $rh_ans->{_filter_name} = $options{_filter_name}; 3142 $rh_ans->{_filter_name} = $options{_filter_name};
3075 3143
3076 my $array = $rh_ans -> {ra_differences}; 3144 my $array = $rh_ans -> {$options{stdin}}; # default ra_differences
3077 my $num = @$array; 3145 my $num = @$array;
3078 my $i; 3146 my $i;
3079 my $max = 0; my $mm; 3147 my $max = 0; my $mm;
3080 for ($i=0; $i< $num; $i++) { 3148 for ($i=0; $i< $num; $i++) {
3081 $mm = $array->[$i] ; 3149 $mm = $array->[$i] ;
3089 $rh_ans->{score} = 0; 3157 $rh_ans->{score} = 0;
3090 my $error = "WeBWorK was unable evaluate your function. Please check that your 3158 my $error = "WeBWorK was unable evaluate your function. Please check that your
3091 expression doesn't take roots of negative numbers, or divide by zero."; 3159 expression doesn't take roots of negative numbers, or divide by zero.";
3092 $rh_ans->throw_error('EVAL',$error); 3160 $rh_ans->throw_error('EVAL',$error);
3093 } else { 3161 } else {
3094 $rh_ans->{score} = ($max < $options{tolerance} ) ? 1: 0; # 1 if the array is close to 0; 3162 $rh_ans->{$options{stdout}} = ($max < $options{tolerance} ) ? 1: 0; # set 'score' to 1 if the array is close to 0;
3095 } 3163 }
3096 $rh_ans; 3164 $rh_ans;
3097} 3165}
3098 3166
3099=head4 best_approx_parameters 3167=head4 best_approx_parameters
3289=cut 3357=cut
3290 3358
3291sub calculate_difference_vector { 3359sub calculate_difference_vector {
3292 my $rh_ans = shift; 3360 my $rh_ans = shift;
3293 my %options = @_; 3361 my %options = @_;
3362 assign_option_aliases( \%options,
3363 );
3364 set_default_options( \%options,
3365 allow_unknown_options => 1,
3366 stdin1 => 'rf_student_ans',
3367 stdin2 => 'rf_correct_ans',
3368 stdout => 'ra_differences',
3369 debug => 0,
3370 tolType => 'absolute',
3371 error_msg_flag => 1,
3372 );
3294 # initialize 3373 # initialize
3295 my $rf_fun = $rh_ans -> {rf_student_ans}; 3374 $rh_ans->{_filter_name} = 'calculate_difference_vector';
3296 my $rf_correct_fun = $rh_ans -> {rf_correct_ans}; 3375 my $rf_fun = $rh_ans -> {$options{stdin1}}; # rf_student_ans by default
3376 my $rf_correct_fun = $rh_ans -> {$options{stdin2}}; # rf_correct_ans by default
3297 my $ra_parameters = $rh_ans ->{ra_parameters}; 3377 my $ra_parameters = $rh_ans -> {ra_parameters};
3298 my @evaluation_points = @{$rh_ans->{evaluation_points} }; 3378 my @evaluation_points = @{$rh_ans->{evaluation_points} };
3299 my @parameters = (); 3379 my @parameters = ();
3300 @parameters = @$ra_parameters if defined($ra_parameters) and ref($ra_parameters) eq 'ARRAY'; 3380 @parameters = @$ra_parameters if defined($ra_parameters) and ref($ra_parameters) eq 'ARRAY';
3301 my $errors = undef; 3381 my $errors = undef;
3302 my @zero_params=(); 3382 my @zero_params = ();
3303 for(my $i=1;$i<=@{$ra_parameters};$i++){push(@zero_params,0); } 3383 for (my $i=1;$i<=@{$ra_parameters};$i++) {
3384 push(@zero_params,0);
3385 }
3304 my @differences = (); 3386 my @differences = ();
3305 my @student_values; 3387 my @student_values;
3306 my @adjusted_student_values; 3388 my @adjusted_student_values;
3307 my @instructorVals; 3389 my @instructorVals;
3308 my ($diff,$instructorVal); 3390 my ($diff,$instructorVal);
3309 # calculate the vector of differences between the test function and the comparison function. 3391 # calculate the vector of differences between the test function and the comparison function.
3322 $errors .= " There is an error in WeBWorK's answer to this problem, please alert your instructor.<br> $err3 " if defined($err3); 3404 $errors .= " There is an error in WeBWorK's answer to this problem, please alert your instructor.<br> $err3 " if defined($err3);
3323 $errors .= " Error detected evaluating instructor answer at (".join(' , ',@vars, @zero_params) ." ) " if defined($options{debug}) and $options{debug}=1 and defined($err3); 3405 $errors .= " Error detected evaluating instructor answer at (".join(' , ',@vars, @zero_params) ." ) " if defined($options{debug}) and $options{debug}=1 and defined($err3);
3324 unless (defined($err1) or defined($err2) or defined($err3) ) { 3406 unless (defined($err1) or defined($err2) or defined($err3) ) {
3325 $diff = ( $inVal - ($correctVal -$instructorVal ) ) - $instructorVal; #prevents entering too high a number? 3407 $diff = ( $inVal - ($correctVal -$instructorVal ) ) - $instructorVal; #prevents entering too high a number?
3326 #warn "taking the difference of ", $inVal, " and ", $correctVal, " is ", $diff; 3408 #warn "taking the difference of ", $inVal, " and ", $correctVal, " is ", $diff;
3327 if (defined($options{tolType}) and $options{tolType} eq 'relative' ) { #relative tolerance 3409 if ( $options{tolType} eq 'relative' ) { #relative tolerance
3328 #warn "diff = $diff"; 3410 #warn "diff = $diff";
3329 #$diff = ( $inVal - ($correctVal-$instructorVal ) )/abs($instructorVal) -1 if abs($instructorVal) > $options{zeroLevel}; 3411 #$diff = ( $inVal - ($correctVal-$instructorVal ) )/abs($instructorVal) -1 if abs($instructorVal) > $options{zeroLevel};
3330 $diff = ( $inVal - ($correctVal-$instructorVal ) )/$instructorVal -1 if abs($instructorVal) > $options{zeroLevel}; 3412 $diff = ( $inVal - ($correctVal-$instructorVal ) )/$instructorVal -1 if abs($instructorVal) > $options{zeroLevel};
3331 #$diff = ( $inVal - ($correctVal-$instructorVal- $instructorVal ) )/abs($instructorVal) if abs($instructorVal) > $options{zeroLevel}; 3413 #$diff = ( $inVal - ($correctVal-$instructorVal- $instructorVal ) )/abs($instructorVal) if abs($instructorVal) > $options{zeroLevel};
3332 #warn "diff = $diff, ", abs( &$rf_correct_fun(@inputs) ) , "-- $correctVal"; 3414 #warn "diff = $diff, ", abs( &$rf_correct_fun(@inputs) ) , "-- $correctVal";
3339 push(@student_values,$inVal); 3421 push(@student_values,$inVal);
3340 push(@adjusted_student_values,( $inVal - ($correctVal -$instructorVal) ) ); 3422 push(@adjusted_student_values,( $inVal - ($correctVal -$instructorVal) ) );
3341 push(@differences, $diff); 3423 push(@differences, $diff);
3342 push(@instructorVals,$instructorVal); 3424 push(@instructorVals,$instructorVal);
3343 } 3425 }
3344 $rh_ans ->{ra_differences} = \@differences; 3426 if ($errors eq '' or $options{error_msg_flag} ) {
3427 $rh_ans ->{$options{stdout}} = \@differences;
3345 $rh_ans ->{ra_student_values} = \@student_values; 3428 $rh_ans ->{ra_student_values} = \@student_values;
3346 $rh_ans ->{ra_adjusted_student_values} = \@adjusted_student_values; 3429 $rh_ans ->{ra_adjusted_student_values} = \@adjusted_student_values;
3347 $rh_ans->{ra_instructor_values}=\@instructorVals; 3430 $rh_ans->{ra_instructor_values}=\@instructorVals;
3348 $rh_ans->throw_error('EVAL', $errors) if defined($errors); 3431 $rh_ans->throw_error('EVAL', $errors) if defined($errors);
3432 } else {
3433
3434 } # no output if error_msg_flag is set to 0.
3435
3436
3349 $rh_ans; 3437 $rh_ans;
3350} 3438}
3351 3439
3352=head4 fix_answer_for_display 3440=head4 fix_answer_for_display
3353 3441
3614 'stdin' => 'student_ans', 3702 'stdin' => 'student_ans',
3615 'stdout' => 'student_ans', 3703 'stdout' => 'student_ans',
3616 'ra_vars' => [qw( x y )], 3704 'ra_vars' => [qw( x y )],
3617 'debug' => 0, 3705 'debug' => 0,
3618 '_filter_name' => 'check_syntax', 3706 '_filter_name' => 'check_syntax',
3707 error_msg_flag => 1,
3619 ); 3708 );
3620 #initialize 3709 #initialize
3621 $rh_ans->{_filter_name} = $options{_filter_name}; 3710 $rh_ans->{_filter_name} = $options{_filter_name};
3622 unless ( defined( $rh_ans->{$options{stdin}} ) ) { 3711 unless ( defined( $rh_ans->{$options{stdin}} ) ) {
3623 warn "Check_syntax requires an equation in the field '$options{stdin}' or input"; 3712 warn "Check_syntax requires an equation in the field '$options{stdin}' or input";
3627 my $in = $rh_ans->{$options{stdin}}; 3716 my $in = $rh_ans->{$options{stdin}};
3628 my $parser = new AlgParserWithImplicitExpand; 3717 my $parser = new AlgParserWithImplicitExpand;
3629 my $ret = $parser -> parse($in); #for use with loops 3718 my $ret = $parser -> parse($in); #for use with loops
3630 3719
3631 if ( ref($ret) ) { ## parsed successfully 3720 if ( ref($ret) ) { ## parsed successfully
3632 $parser -> tostring(); 3721 # $parser -> tostring(); # FIXME? was this needed for some reason?????
3633 $parser -> normalize(); 3722 $parser -> normalize();
3634 $rh_ans -> input( $parser -> tostring() ); 3723 $rh_ans -> {$options{stdout}} = $parser -> tostring();
3635 $rh_ans -> {preview_text_string} = $in; 3724 $rh_ans -> {preview_text_string} = $in;
3636 $rh_ans -> {preview_latex_string} = $parser -> tolatex(); 3725 $rh_ans -> {preview_latex_string} = $parser -> tolatex();
3637 3726
3638 } else { ## error in parsing 3727 } elsif ($options{error_msg_flag} ) { ## error in parsing
3639 3728
3640 $rh_ans->{$options{stdout}} = 'syntax error:'. $parser->{htmlerror}, 3729 $rh_ans->{$options{stdout}} = 'syntax error:'. $parser->{htmlerror},
3641 $rh_ans->{'ans_message'} = $parser -> {error_msg}, 3730 $rh_ans->{'ans_message'} = $parser -> {error_msg},
3642 $rh_ans->{'preview_text_string'} = '', 3731 $rh_ans->{'preview_text_string'} = '',
3643 $rh_ans->{'preview_latex_string'} = '', 3732 $rh_ans->{'preview_latex_string'} = '',
3644 $rh_ans->throw_error('SYNTAX', 'syntax error in answer:'. $parser->{htmlerror} . "$BR" .$parser -> {error_msg}); 3733 $rh_ans->throw_error('SYNTAX', 'syntax error in answer:'. $parser->{htmlerror} . "$BR" .$parser -> {error_msg});
3645 } 3734 } # no output is produced if there is an error and the error_msg_flag is set to zero
3646 $rh_ans; 3735 $rh_ans;
3647 3736
3648} 3737}
3649 3738
3650=head4 check_strings 3739=head4 check_strings

Legend:
Removed from v.2060  
changed lines
  Added in v.2061

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9