some
some <iterable> <block>
Test whether a predicate holds for at least one element of an iterable.
Arguments
<iterable>— a list or any iterable. A bare string is not iterable; convert it first withwords.<block>— a block taking one parameter, declared inside the braces right after{, and bound to the current element on each pass. The block is the predicate; it must yield a bool.
Returns
A bool — true as soon as the predicate yields true for some element,
and false if it never does. An empty iterable yields false.
Control flow
Inside the block, continue skips to the next element,
break stops the iteration early, and
return returns from the enclosing handler or def.
If the predicate yields anything other than a bool, the script stops with a run-time error.
Examples
after command (say) {
require [some [creatures $self] { <c> [ismob $c] }]
do "say There is a mobile in the room."
}
The predicate [ismob $c] runs over the creatures in the owner's room until
one is a mobile. The require guard lets the handler
proceed when at least one is. In the debug world this evaluates to true.
after command (say) {
do "say any empty? [some [list] { <x> [isnull $x] }]"
}
The list is empty, so [some ...] is false and the mob says
"any empty? false."
See also
every— true only if the predicate holds for all elements.ismember,hasabbrev— built-in membership tests without a block.select— keep the elements for which the predicate holds.- Blocks · Iterables and iterables · Control flow