[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 5439 - (download) (as text) (annotate)
Tue Aug 28 21:53:42 2007 UTC (12 years, 5 months ago) by dpvc
File size: 2215 byte(s)
Updated contexts to include a "name" field that at least tracks what
context you started with (though it can be modified and no longer be
the same as the original context).

Remove the individual named variables in the Default.pm file; they are
now available only through the %Parser::Context::Default::context
hash.

Remove the >< and . operators, the <...> parentheses, the norm and
unit functions, and the i, j, and k constants from the Point context.
So the Point context no longer includes vectors and vector
operaterations.

    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::context{Full}->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