tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

filter.scp (457B)


      1 !export filter
      2 -- Keep only elements accepted by a supplied predicate worker.
      3 -- Input: a list; state: the predicate worker. Each call receives one element
      4 -- with the worker's own initial state and returns a tree Boolean: leaf is
      5 -- false, stem leaf is true. A failed call fails the whole filter.
      6 consumer filter
      7   []       @ _         => []
      8   [x | xs] @ predicate => call predicate x as keep in choose keep [x | recur xs @ predicate] recur xs @ predicate