Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/Value.pm
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,12 @@ sub inContext { my $self = shift; $self->context(@_); $self }

#############################################################

#
#
# The address of a Value object (actually ANY perl value).
# Use this to compare two objects to see of they are
# the same object (avoids automatic stringification).
#
sub address { oct(sprintf("0x%p", shift)) }
sub address { Scalar::Util::refaddr(shift) }

sub isBlessed { (Scalar::Util::blessed(shift) // '') ne "" }
sub blessedClass { Scalar::Util::blessed(shift) }
Expand Down
32 changes: 14 additions & 18 deletions macros/answers/answerHints.pl
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ sub AnswerHints {
cmp_options => [],
@options,
);
next if $options{checkTypes} && $correct->type ne $student->type;
next if !$options{processPreview} && $ans->{isPreview};
$wrongList = [$wrongList] unless ref($wrongList) eq 'ARRAY';

foreach my $wrong (@{$wrongList}) {
if (ref($wrong) eq 'CODE') {
if (($ans->{score} < 1 || $options{checkCorrect})
if ((!$options{checkTypes} || $correct->type eq $student->type)
&& ($ans->{score} < 1 || $options{checkCorrect})
&& ($ans->{ans_message} eq "" || $options{replaceMessage}))
{
# Make the call to run the function inside an eval to trap errors
Expand All @@ -166,16 +166,12 @@ sub AnswerHints {
}
}
} else {
$wrong = Value::makeValue($wrong);
if (
(
$ans->{score} < 1
|| $options{checkCorrect}
|| AnswerHints::Compare($correct, $wrong, $ans)
)
&& ($ans->{ans_message} eq "" || $options{replaceMessage})
&& AnswerHints::Compare($wrong, $student, $ans, @{ $options{cmp_options} })
)
unless (Value::isValue($wrong)) {
$wrong = main::Formula($wrong);
$wrong = $wrong->{tree}->Compute if $wrong->{tree}{canCompute};
}
if (($ans->{ans_message} eq "" || $options{replaceMessage})
&& AnswerHints::Compare($wrong, $student, $ans, @{ $options{cmp_options} }))
{
$ans->{ans_message} = $ans->{error_message} = $message;
$ans->{score} = $options{score} if defined $options{score};
Expand All @@ -197,19 +193,19 @@ package AnswerHints;
# and returns true if the two values match and false otherwise.
#
sub Compare {
my $self = shift;
my $other = shift;
my $ans = shift;
$ans = bless { %{$ans}, @_ }, ref($ans); # make a copy
my ($self, $other, $ans, @options) = @_;
return 0 unless $self->typeMatch($other); # make sure these can be compared
$ans = bless { %{$ans}, @options }, ref($ans); # make a copy
$ans->{typeError} = 0;
$ans->{ans_message} = $ans->{error_message} = "";
$ans->{score} = 0;
if (sprintf("%p", $self) ne sprintf("%p", $ans->{correct_value})) {

if ($self->address != $ans->{correct_value}->address) {
$ans->{correct_ans} = $self->string;
$ans->{correct_value} = $self;
$ans->{correct_formula} = Value->Package("Formula")->new($self);
}
if (sprintf("%p", $other) ne sprintf("%p", $ans->{student_value})) {
if ($other->address != $ans->{student_value}->address) {
$ans->{student_ans} = $other->string;
$ans->{student_value} = $other;
$ans->{student_formula} = Value->Package("Formula")->new($other);
Expand Down