[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 5391 - (download) (as text) (annotate)
Sun Aug 19 21:45:47 2007 UTC (12 years, 6 months ago) by dpvc
File size: 2213 byte(s)
Move the context creation into the _init routine so that changes to
main:: are only made at initializaiton time, not load time.

    1 loadMacros('MathObjects.pl');
    2 
    3 =head1 DESCRIPTION
    4 
    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 
   32 =cut
   33 
   34 sub _answerVariableList_init {
   35   #
   36   #  A new context for variable lists
   37   #
   38   $main::context{VariableList} = Parser::Context->new(
   39     operators => {',' => $Parser::Context::Default::fullContext->operators->get(',')},
   40     lists => {'List'  => {class =>'Parser::List::List'}},
   41     parens => {
   42      '(' => {close => ')', type => 'List', formList => 1},
   43      'start' => {close => 'start', type => 'List', formList => 1,
   44                  removable => 1, emptyOK => 1, hidden => 1},
   45      'list'  => {type => 'List', hidden => 1},
   46     },
   47     flags => {
   48       NumberCheck =>
   49         sub {shift->Error("Entries in your list must be variable names")},
   50       formatStudentAnswer => 'evaluated',  # or 'parsed' or 'reduced'
   51     },
   52   );
   53 
   54   main::Context("VariableList");  ### FIXME:  probably should require author to set this explicitly.
   55 }
   56 
   57 
   58 #
   59 #  A shell that calls Formula()->cmp with the right defaults
   60 #
   61 sub variable_cmp {
   62   Value->Package("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