Skip to content

Commit

Permalink
Merge pull request #4 from openwebwork/master
Browse files Browse the repository at this point in the history
grab knowls updates provided by John Jones
  • Loading branch information
mgage committed Aug 20, 2012
2 parents 4a9a8c5 + 29aab04 commit a0face6
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/Parser/Context/Default.pm
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ $functions = {
'atan2' => {class => 'Parser::Function::numeric2'},

'norm' => {class => 'Parser::Function::vector', vectorInput => 1},
'unit' => {class => 'Parser::Function::vector', vectorInput => 1},
'unit' => {class => 'Parser::Function::vector', vectorInput => 1, vector => 1},

'arg' => {class => 'Parser::Function::complex'},
'mod' => {class => 'Parser::Function::complex'},
Expand Down
6 changes: 3 additions & 3 deletions lib/Parser/Function.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ sub substitute {
{$x = $x->substitute; $constant = 0 unless $x->{isConstant}}
return $self->Item("Value")->new($equation,[$self->eval])
if $constant && $context->flag('reduceConstantFunctions');
$self->{isConstant} = 0;
$self->{isConstant} = $constant;
return $self;
}

Expand Down Expand Up @@ -165,7 +165,7 @@ sub checkVector {
return if ($self->checkArgCount(1));
$self->Error("Function '%s' requires a Vector input",$self->{name})
unless $self->{params}[0]->type =~ m/Point|Vector/ || $self->context->flag("allowBadFunctionInputs");
$self->{type} = $Value::Type{number};
$self->{type} = ($self->{def}{vector} ? $self->{params}[0]->typeRef : $Value::Type{number});
}

#
Expand All @@ -181,7 +181,7 @@ sub checkReal {
}

#
# Error if the argument isn't a singe complex number
# Error if the argument isn't a single complex number
# and return a complex.
#
sub checkComplex {
Expand Down
2 changes: 1 addition & 1 deletion lib/Value.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ like equality are "fuzzy", meaning that two items are equal when they are "close
# Initialize the context-- flags set
#
The following are list objects, meaning that they involve delimiters (parentheses)
of some type.
of some type. They get overridden in lib/Parser/Context.pm
lists => {
'Point' => {open => '(', close => ')'},
Expand Down
20 changes: 13 additions & 7 deletions lib/Value/AnswerChecker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ sub cmp_Message {
sub cmp_preprocess {}
sub cmp_postprocess {}

#
# Used to call an object's method as a pre- or post-filter.
# E.g.,
# $cmp->install_pre_filter(\&Value::cmp_call_filter,"cmp_prefilter");
#
sub cmp_call_filter {
my $ans = shift; my $method = shift;
return $ans->{correct_value}->$method($ans,@_);
}

#
# Check for unreduced reduced Unions and Sets
#
Expand Down Expand Up @@ -1552,6 +1562,7 @@ sub splitFormula {
return @formula;
}

#
# Override for List ?
# Return the value if it is defined, otherwise use a default
#
Expand Down Expand Up @@ -1660,16 +1671,11 @@ sub cmp {
$cmp->ans_hash(correct_value => $f);
Parser::Context->current(undef,$current);
}
$cmp->install_pre_filter(\&Value::Formula::cmp_call_filter,"cmp_prefilter");
$cmp->install_post_filter(\&Value::Formula::cmp_call_filter,"cmp_postfilter");
$cmp->install_pre_filter(\&Value::cmp_call_filter,"cmp_prefilter");
$cmp->install_post_filter(\&Value::cmp_call_filter,"cmp_postfilter");
return $cmp;
}

sub cmp_call_filter {
my $ans = shift; my $method = shift;
return $ans->{correct_value}->$method($ans,@_);
}

sub cmp_prefilter {
my $self = shift; my $ans = shift;
$ans->{_filter_name} = "fetch_previous_answer";
Expand Down
6 changes: 4 additions & 2 deletions lib/Value/Formula.pm
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ sub compare {
## FIXME: insert additional values if vars in use in formula aren't all the vars in the context
my $points = $l->{test_points} || $l->createRandomPoints(undef,$l->{test_at});
my $lvalues = $l->{test_values} || $l->createPointValues($points,1,1);
my $rvalues = $r->createPointValues($points,0,1,$l->{checkUndefinedPoints});
my $rvalues = $r->createPointValues($points,0,1,$l->getFlag("checkUndefinedPoints"));
#
# Note: $l is bigger if $r can't be evaluated at one of the points
#
$l->{domainMismatch} = ($rvalues ? 0 : 1);
return 1 unless $rvalues;

my ($i, $cmp);
Expand Down Expand Up @@ -328,7 +330,7 @@ sub createRandomPoints {
my $points = []; my $values = []; my $num_undef = 0;
if ($include) {
push(@{$points},@{$include});
push(@{$values},@{$self->createPointValues($include,1,$cacheResults,$self->{checkundefinedPoints})});
push(@{$values},@{$self->createPointValues($include,1,$cacheResults,$checkUndef)});
}
my (@P,@p,$v,$i); my $k = 0;
while (scalar(@{$points}) < $num_points+$num_undef && $k < 10) {
Expand Down
12 changes: 10 additions & 2 deletions macros/PGbasicmacros.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2138,15 +2138,23 @@ sub helpLink {
'unit' => 'Units.html',
'syntax' => 'Syntax.html',
);

my $infoRef = '';
my $refhold='';
for my $ref (keys %typeHash) {
if ( $type =~ /$ref/i) {
$infoRef = $typeHash{$ref};
$refhold=$ref;
last;
}
}
# If infoRef is still '', we give up
# We use different help files in some cases when BaseTenLog is set
if(PG_restricted_eval(q/$envir{useBaseTenLog}/)) {
$infoRef = 'Entering-Logarithms10.html' if($refhold eq 'log');
$infoRef = 'Entering-Formulas10.html' if($refhold eq 'formula');
}

# If infoRef is still '', we give up and just print plain text
return $customstring unless ($infoRef);
return knowlLink( $envir{'localHelpURL'}.$infoRef, $customstring);
# Old way of doing this:
Expand Down
8 changes: 6 additions & 2 deletions macros/Parser.pl
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,18 @@ =head2 Compute

# ^function Compute
# ^uses Formula
# ^uses Value::contextSet
sub Compute {
my $string = shift;
my $formula = Formula($string);
$formula = $formula->{tree}->Compute if $formula->{tree}{canCompute};
if (scalar(@_) || $formula->isConstant) {
my $f = $formula;
my $f = $formula; my $context = $formula->context;
$formula = $formula->eval(@_);
$formula->{original_formula} = $f;
my $flags = Value::contextSet($context,reduceConstants => 0, reduceConstantFunctions => 0);
$formula->{original_formula} = $f->substitute(@_);
$string = $formula->{original_formula}->string;
Value::contextSet($context,$flags);
}
$formula->{correct_ans} = $string;
return $formula;
Expand Down
12 changes: 6 additions & 6 deletions macros/parserCustomization.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ =head1 DESCRIPTION
customization for the Parser that you want for your course
here. For example, you can make vectors display using
ijk notation (and force students to use it for entering
vectors) by uncommenting:
vectors) by using:
$context{Vector} = Parser::Context->getCopy("Vector");
$context{Vector}->flags->set(ijk=>1);
$context{Vector}->parens->remove('<');
To allow vectors to be entered with parens (and displayed with
parens) rather than angle-brakets, uncomment
parens) rather than angle-brakets, use
$context{Vector} = Parser::Context->getCopy("Vector");
$context{Vector}->{cmpDefaults}{Vector} = {promotePoints => 1};
$context{Vector}->lists->set(Vector=>{open=>'(', close=>')'});
(This actually just turns points into vectors in the answer checker
for vectors, and displays vectors using parens rather than angle
brakets. The student is really still entering what the Parser
thinks is a point, but since points get promoted automatically
in the Value package, that should work. But if a problem checks
if a student's value is actually a Vector, that will not be true.)
brackets. The student is really still entering what MathObjects
thinks is a point, but since points get promoted automatically, that
should work. But if a problem checks if a student's value is actually
a Vector, that will not be true.)
=cut

Expand Down

0 comments on commit a0face6

Please sign in to comment.