Documentation for package rsm.filter


Author : R. Scott McIntire

Version: 1.1

Overview:

This package provides filtering and mapping functions.

REQUIRES: package rsm.queue.

Export Summary:

filter    : Filter a list based on a predicate.
flatten   : Flatten a tree to a list.
linearize : Flatten a tree removing duplicates.
map-tree  : Map a function over the leaves of a tree.
prune-tree: Prune a tree using a predicate.
tree-hom  : Create a function which prunes and transforms trees.
tree-sig  : Create a tree of the same structure with t in every leaf.

filter   (ls pruner)

Return a new list formed from selecting only those elements of <list> that do
not satisfy <pruner>.  The order of the elements is preserved.
Example: (rsm.filter:filter '(1 2 3 4 5) #'evenp)
(1 3 5)

flatten   (tree)

Flattens a tree to a list.
 Example: (rsm.filter:flatten '(1 2 (3 4 (5) 6 7) 8))
          '(1 2 3 4 5 6 7 8)

linearize   (tree &key (from-end nil) (test #'eql))

Linearize a tree, removing duplicates (determined equal by <test>).  If
from-end is non null, then duplicate entries are removed from the end rather
than the beginning of the resulting list.
Example: (rsm.filter:linearize '(a b (c d (e f a) d c w q b)))
(e f a d c w q b)
Example: (rsm.filter:linearize '(a b (c d (e f a) d c w q b)) :from-end t)
(a b c d e f w q)

map-tree   (tree func)

Maps the function <func> over the leaves of tree <tree>.
Example: (rsm.filter:map-tree '(1 2 (3 4 (5) 6 7) 8) #'1+)
(2 3 (4 5 (6) 7 8) 9)

prune-tree   (tree pruner)

Returns a pruned version of <tree> where pruned elements satisfy the
predicate, <pruner>.
Example: (rsm.filter:prune-tree '(1 2 (3 4 (5) (6 7) 4) 2) #'oddp)
(2 (4 (6) 4) 2)

tree-hom   (pruner transformer)

Returns a function which takes a tree and returns a pruned, transformed copy.
The tree will be pruned by <pruner> at the leafs and each leaf (that remains)
will be transformed by <transformer>.
Example: (setf *prune* (rsm.filter:tree-hom #'evenp #'(lambda (x) (+ x 10))))
(funcall *prune* '(1 2 3 (3 4 5 (5 6 7) (7) 8 (9 10)))) (11 13 (13 15 (15 17) (17) (19)))

tree-sig   (tree)

Returns the same tree as <tree> with the value t in every leaf.
Example: (rsm.filter:tree-sig '(1 2 (3 4) 6)
(t t (t t) t)