From: dpvc v. a. <we...@ma...> - 2005-12-31 02:44:52
|
Log Message: ----------- Now that the parser accepts multi-character variables, there is no need for the special treatment of dx. Also, allow the context to specify the default variable to use, and if not available, take the LAST varaible alphabetically, not the first. (x is more likely to be last, and the author might have added dx as a variable so that it will not cause an error if used in other answers in the problem, for example.) Modified Files: -------------- pg/macros: parserDifferenceQuotient.pl Revision Data ------------- Index: parserDifferenceQuotient.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserDifferenceQuotient.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -Lmacros/parserDifferenceQuotient.pl -Lmacros/parserDifferenceQuotient.pl -u -r1.4 -r1.5 --- macros/parserDifferenceQuotient.pl +++ macros/parserDifferenceQuotient.pl @@ -13,7 +13,7 @@ # is not fully reduced. # # Use DifferenceQuotient(formula) to create a difference equation -# object. If the context has more than one variable, the first one +# object. If the context has more than one variable, the last one # alphabetically is used to form the dx. Otherwise, you can specify # the variable used for dx as the second argument to # DifferenceQuotient(). You could use a variable like h instead of @@ -40,20 +40,14 @@ sub new { my $self = shift; my $class = ref($self) || $self; - my $formula = shift; - my $dx = shift || 'd'.($$Value::context->variables->names)[0]; + my $formula = shift; my $current = $$Value::context; + my $dx = shift || $current->flag('diffQuotientVar') || 'd'.($current->variables->names)[-1]; # # Save the original context, and make a copy to which we # add a variable for 'dx' # - my $current = $$Value::context; my $context = main::Context($current->copy); - unless ($context->variables->get($dx)) { - $context->{_variables}->{pattern} = $context->{_variables}->{namePattern} = - $dx . '|' . $context->{_variables}->{pattern}; - $context->update; - $context->variables->add($dx=>'Real'); - } + $context->variables->add($dx=>'Real') unless ($context->variables->get($dx)); $q = bless $self->SUPER::new($formula), $class; $q->{isValue} = 1; $q->{isFormula} = 1; $q->{dx} = $dx; main::Context($current); # put back the original context; |