Expression | Value | (filter
even?
'(1 2 3 4 5)) | (2 4) | (filter
(negate even?)
'(1 2 3 4 5)) | (1 3 5) | (ol
(map li
(filter string?
(list
1 'a "First" "Second" 3)))) |
- First
- Second
| Same as above | <ol>
<li>First</li> <li>Second</li>
</ol> |
| | In the first row we filter the first five natural numbers with the even? predicate. In the second row, we filter the same list of numbers with the odd? predicate.
Rather than using the name odd? we form it by calculating (negate even?) . We have
seen the higher-order function negate earlier in this lecture. The third and final example illustrates the filtering of a list of atoms with the string? predicate.
Only strings pass the filter, and the resulting list of strings is rendered in an ordered list by
means of the mirror function of the ol HTML element. |