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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5373 - (download) (as text) (annotate)
Sun Aug 19 02:01:57 2007 UTC (12 years, 3 months ago) by dpvc
File size: 2119 byte(s)
Normalized comments and headers to that they will format their POD
documentation properly.  (I know that the POD processing was supposed
to strip off the initial #, but that doesn't seem to happen, so I've
added a space throughout.)

    1 loadMacros('MathObjects.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 =cut
   35 
   36 #
   37 #  A new context for variable lists
   38 #
   39 $context{VariableList} = Parser::Context->new(
   40   operators => {',' => $Parser::Context::Default::fullContext->operators->get(',')},
   41   lists => {'List'  => {class =>'Parser::List::List'}},
   42   parens => {
   43    '(' => {close => ')', type => 'List', formList => 1},
   44    'start' => {close => 'start', type => 'List', formList => 1,
   45                removable => 1, emptyOK => 1, hidden => 1},
   46    'list'  => {type => 'List', hidden => 1},
   47   },
   48   flags => {
   49     NumberCheck =>
   50       sub {shift->Error("Entries in your list must be variable names")},
   51     formatStudentAnswer => 'evaluated',  # or 'parsed' or 'reduced'
   52   },
   53 );
   54 Context("VariableList");
   55 
   56 #
   57 #  A shell that calls Formula()->cmp with the right defaults
   58 #
   59 sub variable_cmp {
   60   Value->Package("Formula")->new(shift)->cmp(
   61     ordered => 1,
   62     entry_type =>'a variable',
   63     list_type => 'a list',
   64     implicitList => 0,
   65     @_
   66   );
   67 }
   68 
   69 #
   70 #  Handy routine to set up variables
   71 #
   72 sub addVariables {
   73   my $context = Context();
   74   foreach my $v (@_) {$context->variables->add($v=>'Real')}
   75 }
   76 
   77 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9