find.scp (534B)
1 !export find 2 -- Return the first list element accepted by a supplied predicate worker. 3 -- Input: a list; state: predicate descriptor. Each call uses the predicate's 4 -- own initial state and returns a tree Boolean (leaf false, stem leaf true). 5 -- Result: leaf if no match; stem element if found, including stem leaf if 6 -- the matched element is leaf. Stop at the first match; failures propagate. 7 consumer find 8 [] @ _ => leaf 9 [x | xs] @ predicate => call predicate x as keep in choose keep stem x recur xs @ predicate