Parent Directory
|
Revision Log
Minor documentation changes. Use html entity to represent dollar sign on the web.
1 loadMacros('Parser.pl'); 2 3 sub _answerVariableList_init {}; # don't reload this file 4 5 =head1 DESCRIPTION 6 7 ###################################################################### 8 # 9 # This answer checker compares the student answer to a list of 10 # variable names (so, for example, you can ask for what values a 11 # given function depends on). 12 # 13 # Use addVariables() to create the list of variables that from which 14 # the student can choose, and then use variable_cmp() to generate the 15 # answer checker. If the formula passed to variable_cmp contains 16 # parentheses around the list, then the student's answer must as 17 # well. 18 # 19 # You can also include additional parameters to variable_cmp. These 20 # can be any of the flags appropriate for List() answer checker. 21 # 22 # Usage examples: 23 # 24 # addVariables('x','y','z'); 25 # ANS(variable_cmp("(x,y)")); 26 # 27 # addVariables('x','y','z','s','t,); 28 # ANS(variable_cmp("s,t")); 29 # 30 # addVariables('x','y','z'); 31 # ANS(variable_cmp("(x)",showHints=>0,showLengthHints=>0)); 32 # 33 34 # 35 # A new context for variable lists 36 # 37 38 =cut 39 40 41 $context{VariableList} = Parser::Context->new( 42 operators => {',' => Context()->operators->get(',')}, 43 lists => {'List' => {class =>'Parser::List::List'}}, 44 parens => { 45 '(' => {close => ')', type => 'List', formList => 1}, 46 'start' => {close => 'start', type => 'List', formList => 1, 47 removable => 1, emptyOK => 1, hidden => 1}, 48 'list' => {type => 'List', hidden => 1}, 49 }, 50 flags => { 51 NumberCheck => 52 sub {shift->Error("Entries in your list must be variable names")}, 53 formatStudentAnswer => 'evaluated', # or 'parsed' or 'reduced' 54 }, 55 ); 56 Context("VariableList"); 57 58 # 59 # A shell that calls Formula()->cmp with the right defaults 60 # 61 sub variable_cmp { 62 Value::Formula->new(shift)->cmp( 63 ordered => 1, 64 entry_type =>'a variable', 65 list_type => 'a list', 66 implicitList => 0, 67 @_ 68 ); 69 } 70 71 # 72 # Handy routine to set up variables 73 # 74 sub addVariables { 75 my $context = Context(); 76 foreach my $v (@_) {$context->variables->add($v=>'Real')} 77 } 78 79 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |