FILTER

Synopsis
FILTER conditiontemplate data
Description

Outputs a word or list, depending on the type of the data input, containing a subset of the members (for a list) or characters (for a word) of the input. The conditiontemplate input is evaluated once for each member of the data, and it must produce a TRUE or FALSE value. If the value is TRUE, then the corresponding member is included in the output. Otherwise, it is omitted.

In a template, the symbol ?REST represents the portion of the data input to the right of the member currently being used as the ? slot-filler. That is, if the data input is [A B C D E] and the template is being evaluated with ? replaced by B, then ?REST would be replaced by [C D E]. If multiple parallel slots are used, then (?REST 1) goes with ?1, etc.

In a template, the symbol # represents the position in the data input of the member currently being used as the ? slot-filler. That is, if the data input is [A B C D E] and the template is being evaluated with ? replaced by B, then # would be replaced by 2.

Example
TO VOWELP :arg
  IF :arg="a [OUTPUT "true]
  IF :arg="e [OUTPUT "true]
  IF :arg="i [OUTPUT "true]
  IF :arg="o [OUTPUT "true]
  IF :arg="u [OUTPUT "true]
  OUTPUT "false
END

PRINT FILTER "vowelp "elephant
eea

SourceForge.net Logo