Skip to content

Commit 90fd2cc

Browse files
authored
Merge pull request #1272 from Alex-Jordan/restructure-pod-macros-answers
Restructire the POD of macros (answers)
2 parents f630693 + 64e218a commit 90fd2cc

13 files changed

+221
-255
lines changed

macros/answers/ConditionalHint.pl

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11

2-
=head1 ConditionalHint.pl
2+
=head1 NAME
33
4-
=head2 NAME
5-
6-
C<ConditionalHint.pl> - Allows a hint to be revealed after a student
4+
ConditionalHint.pl - Allows a hint to be revealed after a student
75
has entered an answer correctly.
86
9-
=head2 DESCRIPTION
7+
=head1 DESCRIPTION
108
119
The subroutine C<ConditionalHint()> allows a hint to be revealed
1210
after a student has entered an answer correctly. It is useful
@@ -17,9 +15,9 @@ =head2 DESCRIPTION
1715
A subroutine C<IsAnswerCorrect()> that returns 0 or 1 is also
1816
provided.
1917
20-
=head2 USAGE
18+
=head1 FUNCTIONS
2119
22-
=head3 Synopsis of ConditionalHint
20+
=head2 ConditionalHint
2321
2422
loadMacros("ConditionalHint.pl");
2523
@@ -102,10 +100,6 @@ =head3 Complete Working Example of ConditionalHint
102100
103101
ENDDOCUMENT();
104102
105-
=head2 AUTHOR
106-
107-
Paul Pearson
108-
109103
=cut
110104

111105
sub _ConditionalHint_init { }; # don't reload this file
@@ -142,14 +136,8 @@ sub IsAnswerCorrect {
142136
@_
143137
);
144138

145-
# my $name_of_correct_answer = shift;
146-
# my $answer_rule_number = shift;
147-
148-
# return $name_of_correct_answer->cmp()->evaluate($inputs_ref->{ANS_NUM_TO_NAME($answer_rule_number)})->{score};
149-
150139
return $options{ans_name}->cmp()->evaluate($inputs_ref->{ ANS_NUM_TO_NAME($options{ans_number}) })->{score};
151140

152141
}
153142

154143
1;
155-

macros/answers/Generic.pl

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
#R. Byerly, Texas Tech University, 2005
21

3-
sub _Generic { } #Don't reload this file.
2+
=head1 NAME
43
5-
#Documentation:
4+
Generic.pl - Provide some generic answer checkers.
65
7-
=head1 Generic Answer Checker
6+
=head1 DESCRIPTION
87
9-
(Based on David Cervone's vector_cmp. See
10-
doc/parser/extensions/8-answer.pg under the webwork2 directory.)
11-
Place in macros directory and load this file (Generic.pl) using the
12-
loadMacros command. (To just copy it into a pg file, replace
13-
occurences of "\&" by "~~&".)
8+
This macro provides a set of functions that provide a generic answer checker.
149
15-
Usage:
10+
Usage:
11+
12+
ANS( generic_cmp(<prof_answer>, <optional and mandatory arguments>) );
1613
17-
ANS( generic_cmp(<prof_answer>, <optional and mandatory arguments>) );
1814
where <prof_answer> is a parser object or syntactically correct string
1915
for a parser object.
2016
2117
Mandatory arguments:
2218
23-
type => <type>
19+
type => <type>
20+
2421
where <type> is a recognized parser type (e.g., Number, Point, Vector,
2522
Matrix, etc.)
2623
27-
checker => <checker>
24+
checker => <checker>
25+
2826
where <checker> is a reference to a subroutine that will be passed (in
2927
order) the parsed (and, if possible, evaluated) student answer, the
3028
parsed professor's answer, and a reference to the answer hash. (The
@@ -33,62 +31,55 @@ =head1 Generic Answer Checker
3331
3432
Optional arguments:
3533
36-
correct_ans => <answer_string>
34+
correct_ans => <answer_string>
35+
3736
where <answer_string> is a string that will show up as the correct
3837
answer when solutions are available.
3938
40-
variables_allowed => 0 or 1
39+
variables_allowed => 0 or 1
40+
4141
(default 0 (false). Determines whether student's answer is allowed to
4242
contain variables. In this case the checker must take care of
4343
evaluating it.)
4444
45-
length => n
45+
length => n
46+
4647
where n is the number of elements in an expected answer of type list,
4748
vector, or points. Returns error message to student if answer of wrong
4849
length is entered.
4950
51+
=head1 SYNOPSIS
5052
51-
####################Example:##########################
52-
DOCUMENT(); # This should be the first executable line in the problem.
53+
DOCUMENT();
5354
54-
loadMacros(
55-
"PG.pl",
56-
"PGbasicmacros.pl",
57-
"PGanswermacros.pl",
58-
"Parser.pl",
59-
"Generic.pl",
60-
);
55+
loadMacros("PG.pl", "PGbasicmacros.pl", "PGanswermacros.pl", "Parser.pl", "Generic.pl");
6156
62-
TEXT(&beginproblem);
57+
Context("Vector");
58+
$A=Vector(1,2,1);
59+
$B=Vector(1,3,1);
60+
$C=Vector(1,4,1);
6361
64-
Context("Vector");
65-
$A=Vector(1,2,1);
66-
$B=Vector(1,3,1);
67-
$C=Vector(1,4,1);
62+
BEGIN_TEXT
63+
Show that the vectors \(\{$A->TeX\}, \{$B->TeX\}, \{$C->TeX\}\) do
64+
not span \(R^3\) by giving a vector not in their span:
65+
\{ans_rule()\}
66+
END_TEXT
6867
69-
BEGIN_TEXT
70-
Show that the vectors \(\{$A->TeX\}, \{$B->TeX\}, \{$C->TeX\}\) do
71-
not span \(R^3\) by giving a vector not in their span:
72-
\{ans_rule()\}
73-
END_TEXT
68+
sub check {
69+
my $stu=shift;
70+
$x1=$stu->extract(1); $x3=$stu->extract(3);
71+
$x1 != $x3; #any vectors with different 1st and 3rd coordinates
72+
}
7473
75-
#Easy to get by guessing!
76-
77-
sub check{
78-
my $stu=shift();
79-
$x1=$stu->extract(1); $x3=$stu->extract(3);
80-
$x1 != $x3; #any vectors with different 1st and 3rd coordinates
81-
}
74+
ANS(generic_cmp("23",type => 'Vector', length => 3, checker => ~~&check));
8275
83-
ANS(generic_cmp("23",type => 'Vector', length => 3, checker => ~~&check));
76+
ENDDOCUMENT();
8477
85-
ENDDOCUMENT(); # This should be the last executable line in the problem.
86-
87-
####################End of Example########################
78+
=head1 FUNCTIONS
8879
8980
=cut
9081

91-
#End of Documentation
82+
sub _Generic_init { } # don't reload this file.
9283

9384
#From parserUtils.pl:
9485
sub protectHTML {
@@ -100,6 +91,10 @@ sub protectHTML {
10091

10192
}
10293

94+
=head2 generic_cmp
95+
96+
=cut
97+
10398
sub generic_cmp {
10499
my $v = shift;
105100
my %opts = @_;
@@ -120,6 +115,10 @@ sub generic_cmp {
120115
return $ans;
121116
}
122117

118+
=head2 generic_cmp_check
119+
120+
=cut
121+
123122
sub generic_cmp_check {
124123
my $ans = shift;
125124
my $type = $ans->{type};

0 commit comments

Comments
 (0)