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

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

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

Revision 5550 Revision 5551
1loadMacros('MathObjects.pl'); 1=head1 NAME
2 2
3=head1 DESCRIPTION 3answerVariableList.pl - Creates answer checkers that compare the student's
4 4answer to a list of variable names.
5 ######################################################################
6 #
7 # This answer checker compares the student answer to a list of
8 # variable names (so, for example, you can ask for what values a
9 # given function depends on).
10 #
11 # Use addVariables() to create the list of variables that from which
12 # the student can choose, and then use variable_cmp() to generate the
13 # answer checker. If the formula passed to variable_cmp contains
14 # parentheses around the list, then the student's answer must as
15 # well.
16 #
17 # You can also include additional parameters to variable_cmp. These
18 # can be any of the flags appropriate for List() answer checker.
19 #
20 # Usage examples:
21 #
22 # addVariables('x','y','z');
23 # ANS(variable_cmp("(x,y)"));
24 #
25 # addVariables('x','y','z','s','t,);
26 # ANS(variable_cmp("s,t"));
27 #
28 # addVariables('x','y','z');
29 # ANS(variable_cmp("(x)",showHints=>0,showLengthHints=>0));
30 #
31 5
32=cut 6=cut
7
8loadMacros('MathObjects.pl');
33 9
34sub _answerVariableList_init { 10sub _answerVariableList_init {
35 # 11 #
36 # A new context for variable lists 12 # A new context for variable lists
37 # 13 #
52 ); 28 );
53 29
54 main::Context("VariableList"); ### FIXME: probably should require author to set this explicitly. 30 main::Context("VariableList"); ### FIXME: probably should require author to set this explicitly.
55} 31}
56 32
33=head1 MACROS
57 34
58# 35=head2 variable_cmp
59# A shell that calls Formula()->cmp with the right defaults 36
60# 37 ANS(variable_cmp($var_string, %options))
38
39This answer checker compares the student answer to a list of
40variable names (so, for example, you can ask for what values a
41given function depends on).
42
43Use addVariables() to create the list of variables that from which
44the student can choose, and then use variable_cmp() to generate the
45answer checker. If the formula passed to variable_cmp contains
46parentheses around the list, then the student's answer must as
47well.
48
49You can also include additional parameters to variable_cmp. These
50can be any of the flags appropriate for List() answer checker.
51
52Usage examples:
53
54 addVariables('x','y','z');
55 ANS(variable_cmp("(x,y)"));
56
57 addVariables('x','y','z','s','t,);
58 ANS(variable_cmp("s,t"));
59
60 addVariables('x','y','z');
61 ANS(variable_cmp("(x)",showHints=>0,showLengthHints=>0));
62
63=cut
64
61sub variable_cmp { 65sub variable_cmp {
62 Value->Package("Formula")->new(shift)->cmp( 66 Value->Package("Formula")->new(shift)->cmp(
63 ordered => 1, 67 ordered => 1,
64 entry_type =>'a variable', 68 entry_type =>'a variable',
65 list_type => 'a list', 69 list_type => 'a list',
66 implicitList => 0, 70 implicitList => 0,
67 @_ 71 @_
68 ); 72 );
69} 73}
70 74
71# 75=head2 addVariables
72# Handy routine to set up variables 76
73# 77 addVariables(@vars)
78
79Adds each string in @vars as a varible to the current context.
80
81=cut
82
74sub addVariables { 83sub addVariables {
75 my $context = Context(); 84 my $context = Context();
76 foreach my $v (@_) {$context->variables->add($v=>'Real')} 85 foreach my $v (@_) {$context->variables->add($v=>'Real')}
77} 86}
78 87
791; 881;
89

Legend:
Removed from v.5550  
changed lines
  Added in v.5551

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9