| … | |
… | |
| 110 | be_strict(); # an alias for use strict. This means that all global variable must contain main:: as a prefix. |
110 | be_strict(); # an alias for use strict. This means that all global variable must contain main:: as a prefix. |
| 111 | } |
111 | } |
| 112 | |
112 | |
| 113 | |
113 | |
| 114 | |
114 | |
| 115 | sub _PGanswermacros_export { |
115 | #sub _PGanswermacros_export { |
| 116 | my @EXPORT = ( |
116 | # my @EXPORT = ( |
| 117 | '&std_num_cmp', '&std_num_cmp_list', '&std_num_cmp_abs', |
117 | # '&std_num_cmp', '&std_num_cmp_list', '&std_num_cmp_abs', |
| 118 | '&std_num_cmp_abs_list', '&frac_num_cmp', '&frac_num_cmp_list', |
118 | # '&std_num_cmp_abs_list', '&frac_num_cmp', '&frac_num_cmp_list', |
| 119 | '&frac_num_cmp_abs', '&frac_num_cmp_abs_list', '&arith_num_cmp', |
119 | # '&frac_num_cmp_abs', '&frac_num_cmp_abs_list', '&arith_num_cmp', |
| 120 | '&arith_num_cmp_list', '&arith_num_cmp_abs', '&arith_num_cmp_abs_list', |
120 | # '&arith_num_cmp_list', '&arith_num_cmp_abs', '&arith_num_cmp_abs_list', |
| 121 | '&strict_num_cmp', '&strict_num_cmp_list', '&strict_num_cmp_abs', |
121 | # '&strict_num_cmp', '&strict_num_cmp_list', '&strict_num_cmp_abs', |
| 122 | '&strict_num_cmp_abs_list', '&numerical_compare_with_units', |
122 | # '&strict_num_cmp_abs_list', '&numerical_compare_with_units', |
| 123 | '&std_num_str_cmp', '&num_cmp', '&num_rel_cmp', '&NUM_CMP', |
123 | # '&std_num_str_cmp', '&num_cmp', '&num_rel_cmp', '&NUM_CMP', |
| 124 | '&NUM_CMP_LIST', '&adaptive_function_cmp', '&function_cmp', |
124 | # '&NUM_CMP_LIST', '&adaptive_function_cmp', '&function_cmp', |
| 125 | '&function_cmp_up_to_constant', '&function_cmp_abs', |
125 | # '&function_cmp_up_to_constant', '&function_cmp_abs', |
| 126 | '&function_cmp_up_to_constant_abs', '&multivar_function_cmp', |
126 | # '&function_cmp_up_to_constant_abs', '&multivar_function_cmp', |
| 127 | '&fun_cmp', '&FUNCTION_CMP', '&is_array', '&check_syntax', |
127 | # '&fun_cmp', '&FUNCTION_CMP', '&is_array', '&check_syntax', |
| 128 | '&std_num_filter', '&std_num_array_filter', '&function_from_string2', |
128 | # '&std_num_filter', '&std_num_array_filter', '&function_from_string2', |
| 129 | '&is_zero_array', '&best_approx_parameters', |
129 | # '&is_zero_array', '&best_approx_parameters', |
| 130 | '&calculate_difference_vector', '&str_filters', '&remove_whitespace', |
130 | # '&calculate_difference_vector', '&str_filters', '&remove_whitespace', |
| 131 | '&compress_whitespace', '&trim_whitespace', '&ignore_case', |
131 | # '&compress_whitespace', '&trim_whitespace', '&ignore_case', |
| 132 | '&ignore_order', '&std_str_cmp', '&std_str_cmp_list', '&std_cs_str_cmp', |
132 | # '&ignore_order', '&std_str_cmp', '&std_str_cmp_list', '&std_cs_str_cmp', |
| 133 | '&std_cs_str_cmp_list', '&strict_str_cmp', '&strict_str_cmp_list', |
133 | # '&std_cs_str_cmp_list', '&strict_str_cmp', '&strict_str_cmp_list', |
| 134 | '&unordered_str_cmp', '&unordered_str_cmp_list', |
134 | # '&unordered_str_cmp', '&unordered_str_cmp_list', |
| 135 | '&unordered_cs_str_cmp', '&unordered_cs_str_cmp_list', |
135 | # '&unordered_cs_str_cmp', '&unordered_cs_str_cmp_list', |
| 136 | '&ordered_str_cmp', '&ordered_str_cmp_list', '&ordered_cs_str_cmp', |
136 | # '&ordered_str_cmp', '&ordered_str_cmp_list', '&ordered_cs_str_cmp', |
| 137 | '&ordered_cs_str_cmp_list', '&str_cmp', '&STR_CMP', '&checkbox_cmp', |
137 | # '&ordered_cs_str_cmp_list', '&str_cmp', '&STR_CMP', '&checkbox_cmp', |
| 138 | '&radio_cmp', '&store_ans_at', '&DUMMY_ANSWER', '&escapeHTML', |
138 | # '&radio_cmp', '&store_ans_at', '&DUMMY_ANSWER', '&escapeHTML', |
| 139 | '&anstext', '&ansradio', '&mail_answers_to', '&mail_answers_to2', |
139 | # '&anstext', '&ansradio', '&mail_answers_to', '&mail_answers_to2', |
| 140 | '&install_problem_grader', '&std_problem_grader', |
140 | # '&install_problem_grader', '&std_problem_grader', |
| 141 | '&std_problem_grader2', '&avg_problem_grader', '&get_var_array', |
141 | # '&std_problem_grader2', '&avg_problem_grader', '&get_var_array', |
| 142 | '&get_limits_array', '&check_option_list', '&function_invalid_params', |
142 | # '&get_limits_array', '&check_option_list', '&function_invalid_params', |
| 143 | '&is_a_number', '&is_a_fraction', '&is_an_arithmetic_expression', |
143 | # '&is_a_number', '&is_a_fraction', '&is_an_arithmetic_expression', |
| 144 | '&math_constants', '&clean_up_error_msg', '&prfmt', '&pretty_print', |
144 | # '&math_constants', '&clean_up_error_msg', '&prfmt', '&pretty_print', |
| 145 | '&set_default_options', '&assign_option_aliases', |
145 | # '&set_default_options', '&assign_option_aliases', |
| 146 | ); |
146 | # ); |
| 147 | @EXPORT; |
147 | # @EXPORT; |
| 148 | } |
148 | #} |
| 149 | |
149 | |
| 150 | my ($BR, $PAR,$numRelPercentTolDefault,$numZeroLevelDefault,$numZeroLevelTolDefault, |
150 | my ($BR , # convenient localizations. |
| 151 | $numAbsTolDefault,$numFormatDefault,$functRelPercentTolDefault,$functZeroLevelDefault, |
151 | $PAR , |
| 152 | $functZeroLevelTolDefault,$functAbsTolDefault,$functNumOfPoints,$functVarDefault, |
152 | $numRelPercentTolDefault , |
| 153 | $functLLimitDefault, $functULimitDefault, $functMaxConstantOfIntegration, |
153 | $numZeroLevelDefault , |
|
|
154 | $numZeroLevelTolDefault , |
|
|
155 | $numAbsTolDefault , |
|
|
156 | $numFormatDefault , |
|
|
157 | $functRelPercentTolDefault , |
|
|
158 | $functZeroLevelDefault , |
|
|
159 | $functZeroLevelTolDefault , |
|
|
160 | $functAbsTolDefault , |
|
|
161 | $functNumOfPoints , |
|
|
162 | $functVarDefault , |
|
|
163 | $functLLimitDefault , |
|
|
164 | $functULimitDefault , |
|
|
165 | $functMaxConstantOfIntegration |
| 154 | ); |
166 | ); |
| 155 | |
167 | |
| 156 | sub _PGanswermacros_init { |
168 | sub _PGanswermacros_init { |
| 157 | |
169 | |
| 158 | $BR = $main::BR; # convenient localizations. |
170 | $BR = $main::BR; # convenient localizations. |
| 159 | $PAR = $main::PAR; |
171 | $PAR = $main::PAR; |
| 160 | |
172 | |
| 161 | # import defaults |
173 | # import defaults |
| 162 | # these are now imported from the %envir variable |
174 | # these are now imported from the %envir variable |
| 163 | $numRelPercentTolDefault = PG_restricted_eval(q{$main::numRelPercentTolDefault}); |
175 | $numRelPercentTolDefault = $main::numRelPercentTolDefault; |
| 164 | $numZeroLevelDefault = PG_restricted_eval(q{$main::numZeroLevelDefault}); |
176 | $numZeroLevelDefault = $main::numZeroLevelDefault; |
| 165 | $numZeroLevelTolDefault = PG_restricted_eval(q{$main::numZeroLevelTolDefault}); |
177 | $numZeroLevelTolDefault = $main::numZeroLevelTolDefault; |
| 166 | $numAbsTolDefault = PG_restricted_eval(q{$main::numAbsTolDefault}); |
178 | $numAbsTolDefault = $main::numAbsTolDefault; |
| 167 | $numFormatDefault = PG_restricted_eval(q{$main::numFormatDefault}); |
179 | $numFormatDefault = $main::numFormatDefault; |
| 168 | |
180 | |
| 169 | $functRelPercentTolDefault = PG_restricted_eval(q{$main::functRelPercentTolDefault}); |
181 | $functRelPercentTolDefault = $main::functRelPercentTolDefault; |
| 170 | $functZeroLevelDefault = PG_restricted_eval(q{$main::functZeroLevelDefault}); |
182 | $functZeroLevelDefault = $main::functZeroLevelDefault; |
| 171 | $functZeroLevelTolDefault = PG_restricted_eval(q{$main::functZeroLevelTolDefault}); |
183 | $functZeroLevelTolDefault = $main::functZeroLevelTolDefault; |
| 172 | $functAbsTolDefault = PG_restricted_eval(q{$main::functAbsTolDefault}); |
184 | $functAbsTolDefault = $main::functAbsTolDefault; |
| 173 | $functNumOfPoints = PG_restricted_eval(q{$main::functNumOfPoints}); |
185 | $functNumOfPoints = $main::functNumOfPoints; |
| 174 | $functVarDefault = PG_restricted_eval(q{$main::functVarDefault}); |
186 | $functVarDefault = $main::functVarDefault; |
| 175 | $functLLimitDefault = PG_restricted_eval(q{$main::functLLimitDefault}); |
187 | $functLLimitDefault = $main::functLLimitDefault; |
| 176 | $functULimitDefault = PG_restricted_eval(q{$main::functULimitDefault}); |
188 | $functULimitDefault = $main::functULimitDefault; |
| 177 | $functMaxConstantOfIntegration = PG_restricted_eval(q{$main::functMaxConstantOfIntegration}); |
189 | $functMaxConstantOfIntegration = $main::functMaxConstantOfIntegration; |
| 178 | |
190 | |
| 179 | |
191 | |
| 180 | |
192 | |
| 181 | } |
193 | } |
| 182 | |
194 | |
| … | |
… | |
| 2293 | my @VARS = @{ $options{ 'ra_vars'}}; |
2305 | my @VARS = @{ $options{ 'ra_vars'}}; |
| 2294 | warn "VARS = ", join("<>", @VARS) if defined($options{debug}) and $options{debug} ==1; |
2306 | warn "VARS = ", join("<>", @VARS) if defined($options{debug}) and $options{debug} ==1; |
| 2295 | my $originalEqn = $eqn; |
2307 | my $originalEqn = $eqn; |
| 2296 | $eqn = &math_constants($eqn); |
2308 | $eqn = &math_constants($eqn); |
| 2297 | for( my $i = 0; $i < @VARS; $i++ ) { |
2309 | for( my $i = 0; $i < @VARS; $i++ ) { |
|
|
2310 | # This next line is a hack required for 5.6.0 -- it doesn't appear to be needed in 5.6.1 |
|
|
2311 | my ($temp,$er1,$er2) = PG_restricted_eval('"'. $VARS[$i] . '"'); |
| 2298 | $eqn =~ s/\b$VARS[$i]\b/\$VARS[$i]/g; |
2312 | # $eqn =~ s/\b$VARS[$i]\b/\$VARS[$i]/g; |
|
|
2313 | $eqn =~ s/\b$temp\b/\$VARS[$i]/g; |
|
|
2314 | |
| 2299 | } |
2315 | } |
| 2300 | warn "equation evaluated = $eqn",$rh_ans->pretty_print(), "<br>\noptions<br>\n", |
2316 | warn "equation evaluated = $eqn",$rh_ans->pretty_print(), "<br>\noptions<br>\n", |
| 2301 | pretty_print(\%options) |
2317 | pretty_print(\%options) |
| 2302 | if defined($options{debug}) and $options{debug} ==1; |
2318 | if defined($options{debug}) and $options{debug} ==1; |
| 2303 | my ($function_sub,$PG_eval_errors, $PG_full_errors) = PG_answer_eval( q! |
2319 | my ($function_sub,$PG_eval_errors, $PG_full_errors) = PG_answer_eval( q! |
| … | |
… | |
| 3355 | $problem_result{score} = $allAnswersCorrectQ; |
3371 | $problem_result{score} = $allAnswersCorrectQ; |
| 3356 | |
3372 | |
| 3357 | # I don't like to put in this bit of code. |
3373 | # I don't like to put in this bit of code. |
| 3358 | # It makes it hard to construct error free problem graders |
3374 | # It makes it hard to construct error free problem graders |
| 3359 | # I would prefer to know that the problem score was numeric. |
3375 | # I would prefer to know that the problem score was numeric. |
| 3360 | unless ($problem_state{recorded_score} =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ ) { |
3376 | unless (defined($problem_state{recorded_score}) and $problem_state{recorded_score} =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ ) { |
| 3361 | $problem_state{recorded_score} = 0; # This gets rid of non-numeric scores |
3377 | $problem_state{recorded_score} = 0; # This gets rid of non-numeric scores |
| 3362 | } |
3378 | } |
| 3363 | # |
3379 | # |
| 3364 | if ($allAnswersCorrectQ == 1 or $problem_state{recorded_score} == 1) { |
3380 | if ($allAnswersCorrectQ == 1 or $problem_state{recorded_score} == 1) { |
| 3365 | $problem_state{recorded_score} = 1; |
3381 | $problem_state{recorded_score} = 1; |