## WeBWorK Problems

### Subroutine return type in custom answer checker

by Steven Fiedler -
Number of replies: 1

I would appreciate learning more about the return types for subroutines as used within the custom answer checker.  Below is code that was distilled from the bottom example on the wiki for the Custom Answer Checker page. The simple "override" subroutine does not appear to have any effect on the answer checker.  The nested (wrap) routine on the other hand, behaves in the expected manner by permitting other answers, say 4.  For clarity, it would be nice to cast the return value in the simple "override" routine to permit its direct use.

DOCUMENT();
$val=Real(3); BEGIN_TEXT Enter the number 3: \{ans_rule(15)\} END_TEXT ANS($val->cmp(checker => override() ));
#  ANS($val->cmp(checker => wrap() )); sub override { return 1; } sub wrap { return sub { return override(); }; } ENDDOCUMENT(); In reply to Steven Fiedler ### Re: Subroutine return type in custom answer checker by Davide Cervone - 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 ));

$override = sub {return 1}; ANS($val->cmp(checker => $override ));  or ANS($val->cmp(checker => sub {