WeBWorK Problems

Subroutine return type in custom answer checker

Re: Subroutine return type in custom answer checker

by Davide Cervone -
Number of replies: 0
The problem is that you are not passing the subroutine as the checker, but the return value of the subroutine when called as override(). You need to do either

sub override {return 1}

ANS($val->cmp(checker => ~~&override ));
or

$override = sub {return 1};

ANS($val->cmp(checker => $override ));
or

ANS($val->cmp(checker => sub {
  return 1;
} ));
Many people prefer the latter if they are only using the custom checker once, otherwise, the middle one is good if you are defining the subroutine in a macro file.