Difference between revisions of "Must have filter"

From WeBWorK_wiki
Jump to navigation Jump to search
 
Line 18: Line 18:
   
 
<blockquote> a filter ( a subroutine suitable for use in answer evaluators)</blockquote>
 
<blockquote> a filter ( a subroutine suitable for use in answer evaluators)</blockquote>
  +
  +
'''Note'''
  +
  +
<blockquote>
  +
If called directly from a pg file, one should also install catch_error_filter as a post-filter</blockquote>
  +
   
 
'''Examples'''
 
'''Examples'''
   
 
<blockquote> $new_eval-&gt;install_pre_filter(must_have_filter("sin", 'no', "can't use sin() in this answer"));</blockquote>
 
<blockquote> $new_eval-&gt;install_pre_filter(must_have_filter("sin", 'no', "can't use sin() in this answer"));</blockquote>
  +
<blockquote> $new_eval-&gt;install_post_filter(~~&catch_errors_filter();</blockquote>
  +
   
 
'''Macro Definition File'''
 
'''Macro Definition File'''

Latest revision as of 14:20, 4 September 2013


must_have_filter

Description

Filter for checking that an answer has (or doesn't have) a certain string in it. This can be used to screen answers where you want them in a particular form (e.g., if you allow most functions, but not trig functions in the answer, or if the answer must include some string).

Syntax

must_have_filter(str, yes_no, error_msg)

Params

First argument is the string to have, or not have
Second argument is optional, and tells us whether yes or no
Third argument is the error message to produce (if any).

Returns

a filter ( a subroutine suitable for use in answer evaluators)

Note

If called directly from a pg file, one should also install catch_error_filter as a post-filter


Examples

$new_eval->install_pre_filter(must_have_filter("sin", 'no', "can't use sin() in this answer"));

$new_eval->install_post_filter(~~&catch_errors_filter();


Macro Definition File

[PGasu.pl]