## Sequence Predicates

Sequence Predicates

Four other handy functions are `EVERY`, `SOME`, `NOTANY`, and `NOTEVERY`, which iterate over sequences testing a boolean predicate. The first argument to all these functions is the predicate, and the remaining arguments are sequences. The predicate should take as many arguments as the number of sequences passed. The elements of the sequences are passed to the predicate—one element from each sequence—until one of the sequences runs out of elements or the overall termination test is met: `EVERY` terminates, returning false, as soon as the predicate fails. If the predicate is always satisfied, it returns true. `SOME` returns the first non-`NIL` value returned by the predicate or returns false if the predicate is never satisfied. `NOTANY` returns false as soon as the predicate is satisfied or true if it never is. And `NOTEVERY` returns true as soon as the predicate fails or false if the predicate is always satisfied. Here are some examples of testing just one sequence:

```(every #'evenp #(1 2 3 4 5)) ==> NIL (some #'evenp #(1 2 3 4 5)) ==> T (notany #'evenp #(1 2 3 4 5)) ==> NIL (notevery #'evenp #(1 2 3 4 5)) ==> T```

These calls compare elements of two sequences pairwise:

```(every #'> #(1 2 3 4) #(5 4 3 2)) ==> NIL (some #'> #(1 2 3 4) #(5 4 3 2)) ==> T (notany #'> #(1 2 3 4) #(5 4 3 2)) ==> NIL (notevery #'> #(1 2 3 4) #(5 4 3 2)) ==> T```

Оглавление книги

Генерация: 1.476. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз