I decided that I would try first to get the restricted version to work. It is my
impression that I wrote the context as you suggested, but my proofreading is so
dreadful that I can't guarantee that. In any event, in the file contextLeadingZero.pl
is now stored:
[root@homework macros]# more contextLeadingZero.pl
################################################################################
=head1 NAME
contextLeadingZero.pl - implements contextLimitedNumeric with the additional
feature that decimals need integer before decimal pt
=head1 DESCRIPTION
=cut
loadMacros("contextLimitedNumeric.pl");
$context{LeadingZero} = Parser::Context->getCopy("contextLimitedNumeric");
$context{LeadingZero}=>flags->set(
NumberCheck => sub {
my $self = shift;
$self->Error("Decimals must have a number before the decimal point")
if $self->{value_string} =~ m/^\./;
}
);
I embedded this in the problem as shown below (with error message preceding
file listing.
set1: Problem 3
This set is visible to students.
WeBWorK Error
WeBWorK has encountered a software error while attempting to process this problem. It is likely that there is an error in the problem itself. If you are a student, report this error message to your professor to have it corrected. If you are a professor, please consult the error output below for more information.
Error messages
Error detected while loading [PG]/macros/contextLeadingZero.pl: Can't locate object method "set" via package "flags" (perhaps you forgot to load "flags"?) at line 24 of [PG]/macros/contextLeadingZero.pl, chunk 1 Died within main::compile_file called at line 308 of (eval 1122) from within main::loadMacros called at line 6 of [TMPL]/msprobs/mn+o5-1inter13b.pg
Error details
Problem3 ERROR caught by Translator while processing problem file:msprobs/mn+o5-1inter13b.pg **************** Error detected while loading [PG]/macros/contextLeadingZero.pl: Can't locate object method "set" via package "flags" (perhaps you forgot to load "flags"?) at line 24 of [PG]/macros/contextLeadingZero.pl, chunk 1 Died within main::compile_file called at line 308 of (eval 1122) from within main::loadMacros called at line 6 of [TMPL]/msprobs/mn+o5-1inter13b.pg **************** ------Input Read 1 #DESCRIPTION 2 ##Type of 3 #ENDDESCRIPTION 4 5 DOCUMENT(); 6 loadMacros( 7 "PGstandard.pl", 8 "PGchoicemacros.pl", 9 "PGgraphmacros.pl", 10 "MathObjects.pl", 11 "compoundProblem.pl", 12 "contextCurrency.pl", 13 "unionLists.pl", 14 "unionMacros.pl", 15 "contextLimitedNumeric.pl", 16 "contextLeadingZero.pl", 17 ); 18 Context()->texStrings; 19 TEXT(beginproblem()); 20 $showPartialCorrectAnswers = 1; 21 $a=random(61,69,1); 22 $b=random(31,39,1); 23 $c=random(1,9,1); 24 $ans1= $a/100; 25 $ans2=$b/100; 26 $ans3=$c/100; 27 $ans4=.19; 28 $ans5=.78; 29 Context()->texStrings; 30 BEGIN_TEXT 31 $PAR 32 Write each as a decimal 33 $PAR 34 \( \frac{$a}{100}=\) \{ans_rule(3)\} 35 $PAR 36 \( \frac{$b}{100}= \) \{ans_rule(3)\} 37 $PAR 38 \( \frac{$c}{100}= \) \{ans_rule(2)\} 39 $PAR 40 nineteen hundredths =\{ans_rule(3)\} 41 $PAR 42 seventy-eight hundredths =\{ans_rule(3)\} 43 44 END_TEXT 45 Context("LeadingZero"); 46 #note, this should be modified for .xxx 47 &ANS(Real($ans1)->cmp); 48 &ANS(Real($ans2)->cmp); 49 &ANS(Real($ans3)->cmp); 50 &ANS(Real($ans4)->cmp); 51 &ANS(Real($ans5)->cmp); 52 53 ENDDOCUMENT()Was I supposed to do something about the flags other than what was in the
new context?
Ken,
PS I spent two days at the beach finally reading "Programming Perl" in
more detail (It is amazing how much one can get away with using ordinary
webwork problems with a limited knowledge of Perl) But this one still
eludes me.