Skip to content

Commit

Permalink
MathObject version of the new Boolean context
Browse files Browse the repository at this point in the history
  • Loading branch information
drdrew42 committed Mar 17, 2024
1 parent a9d9280 commit f198985
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions macros/contexts/contextReaction.pl
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,23 @@ sub cmp_postprocess {
if $ans->{showTypeWarnings} && $ans->{student_value}{tree}->type ne 'Reaction';
}

# permit ions to be written at 2+ or simply + or -
# automatically added with cmp_call_filter (hence the additional argument)
sub cmp_prefilter {
my $self = shift; # technically, this is correct_value
my $ans = shift;
# parens are added by MQ when the ion digit leads - swap the order
$ans->{student_ans} =~ s/\^\((\d)([+-])\)/"^(".$2.$1.")"/ge;
# no parens when the ion digit is preceeded by +/-,
# modification is necessary to protect against next regex
$ans->{student_ans} =~ s/\^([+-])(\d)/"^(".$1.$2.")"/ge;
# only ions with no digits remain
$ans->{student_ans} =~ s/\^\(([+-])\)/"^(".$1."1)"/ge;
$ans->{student_ans} =~ s/\^([+-])/"^(".$1."1)"/ge;
warn "modified reaction: $ans->{student_ans}";
return $ans;
}

#
# Since the context only allows things that are comparable, we
# don't really have to check anything. (But if somone added
Expand Down

0 comments on commit f198985

Please sign in to comment.