Parent Directory
|
Revision Log
improved formatting for docs -- these were in pod sections but were all formatted as verbatim sections, and i moved them into normal paragraphs, lists, etc. should make things more readable from the web.
1 =head1 NAME 2 3 answerVariableList.pl - Creates answer checkers that compare the student's 4 answer to a list of variable names. 5 6 =cut 7 8 loadMacros('MathObjects.pl'); 9 10 sub _answerVariableList_init { 11 # 12 # A new context for variable lists 13 # 14 $main::context{VariableList} = Parser::Context->new( 15 operators => {',' => $Parser::Context::Default::context{Full}->operators->get(',')}, 16 lists => {'List' => {class =>'Parser::List::List'}}, 17 parens => { 18 '(' => {close => ')', type => 'List', formList => 1}, 19 'start' => {close => 'start', type => 'List', formList => 1, 20 removable => 1, emptyOK => 1, hidden => 1}, 21 'list' => {type => 'List', hidden => 1}, 22 }, 23 flags => { 24 NumberCheck => 25 sub {shift->Error("Entries in your list must be variable names")}, 26 formatStudentAnswer => 'evaluated', # or 'parsed' or 'reduced' 27 }, 28 ); 29 30 main::Context("VariableList"); ### FIXME: probably should require author to set this explicitly. 31 } 32 33 =head1 MACROS 34 35 =head2 variable_cmp 36 37 ANS(variable_cmp($var_string, %options)) 38 39 This answer checker compares the student answer to a list of 40 variable names (so, for example, you can ask for what values a 41 given function depends on). 42 43 Use addVariables() to create the list of variables that from which 44 the student can choose, and then use variable_cmp() to generate the 45 answer checker. If the formula passed to variable_cmp contains 46 parentheses around the list, then the student's answer must as 47 well. 48 49 You can also include additional parameters to variable_cmp. These 50 can be any of the flags appropriate for List() answer checker. 51 52 Usage 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 65 sub variable_cmp { 66 Value->Package("Formula")->new(shift)->cmp( 67 ordered => 1, 68 entry_type =>'a variable', 69 list_type => 'a list', 70 implicitList => 0, 71 @_ 72 ); 73 } 74 75 =head2 addVariables 76 77 addVariables(@vars) 78 79 Adds each string in @vars as a varible to the current context. 80 81 =cut 82 83 sub addVariables { 84 my $context = Context(); 85 foreach my $v (@_) {$context->variables->add($v=>'Real')} 86 } 87 88 1; 89
aubreyja at gmail dot com | ViewVC Help |
Powered by ViewVC 1.0.9 |