Predicates: In Practice
Predicates can be used as conditions defining the execution of an operation. Hence, predicates must be connected to
-
the “test” input of an OMIF box,
-
to a function that has a test argument.
If a given property or a relation is verified by a predicate, the operation is performed.
Example : Using a Type Predicate as a Test Argument
Here, we want to delete floats from a list with list-filter. List-filter rejects or passes elements from a list, depending on the predicate taken as argument.
It has three default inputs :
-
a predicate, whose default value is numberp
-
a list
-
an action - “reject” or “pass”.
—|—
The floatp predicate and the “reject” option have been assigned to list- filter, so that floats are rejected.
- List-filter tests each element of the list successively.
- If the test is satisfied, the element is either rejected, or passed, depending on the option that was chosen.
- The remaining elements are returned in a list.
—|—
Using a Function on Lambda Mode
A predicate can be a function on “lambda” mode.
—|—
Using a Lambda Function as a Predicate
References :
Contents :