propeller.utils
Useful functions.
bmx-distance
(bmx-distance p1 p2)
A utility function for bmx. Returns the distance between two plushies computed as half of their multiset-distance plus their length difference.
break-up
(break-up gene limit)
A utility function for bmx-related genetic operators. Returns the provided :gap-free plushy with gaps randomly inserted to ensure that no gene is longer than the provided limit.
count-genes
(count-genes plushy)
A utility for best match crossover (bmx). Returns the number of segments between (and before and after) instances of :gap.
count-points
(count-points tree)
Returns the number of points in tree, where each atom and each pair of parentheses counts as a point.
depth
(depth tree)
Returns the height of the nested list called tree. Borrowed idea from here: https://stackoverflow.com/a/36865180/2023312 Works by looking at the path from each node in the tree to the root, and finding the longest one. Note: does not treat an empty list as having any height.
drop-nth
(drop-nth n coll)
drops the nth element from a collection
enforce-gene-length-limit
(enforce-gene-length-limit plushy limit)
A utility function for bmx-related genetic operators. Returns the provided plushy with any over-length genes broken into non-empty pieces, recursively until all genes obey the limit.
ensure-list
(ensure-list thing)
Returns a non-lazy list if passed a seq argument. Otherwise, returns a list containing the argument.
extract-genes
(extract-genes plushy)
A utility for best match crossover (bmx). Returns the segments of the plushy before/between/after instances of :gap.
filter-by-index
(filter-by-index coll idxs)
filters a collection by a list of indices
first-non-nil
(first-non-nil coll)
Returns the first non-nil values from the collection, or returns nil
if the collection is empty or only contains nil
.
gaussian-noise-factor
(gaussian-noise-factor)
Returns gaussian noise of mean 0, std dev 1.
indexof
(indexof element coll)
Returns the first index of an element in a collection. If the element is not present in the collection, returns -1.
log
(log x)
FIXME: write docs
not-lazy
(not-lazy lst)
Returns lst if it is not a seq, or a non-lazy version of lst if it is.
onenum
(onenum thing-or-collection)
If given a number, returns it. If given a collection, returns a member of the collection. Intended for allowing arguments to genetic operators, such as mutation rates, to take collections in addition to single values
perturb-with-gaussian-noise
(perturb-with-gaussian-noise sd n)
Returns n perturbed with std dev sd.
PI
FIXME: write docs
pmapallv
(pmapallv f & colls-args)
A utility for concurrent execution of a function. If :single-thread-mode is truthy in the final arg then this acts like mapv of f on the provided colls. Otherwise it acts like pmap but: 1) the colls should be finite, 2) the returned sequence will not be lazy, and will in fact be a vector, and 3) calls to f may occur in any order, to maximize multicore processor utilization.
pretty-map-println
(pretty-map-println mp)
Takes a map and prints it, with each key/value pair on its own line.
random-instruction
(random-instruction instructions argmap)
Returns a random instruction from a supplied pool of instructions, evaluating ERC-producing functions to a constant literal.
remove-empty-genes
(remove-empty-genes plushy)
A utility function for bmx-related genetic operators. Returns the provided plushy with any empty genes (regions before/between/after instances of :gap) removed.
round
(round x)
FIXME: write docs
seq-zip
added in 1.0
(seq-zip root)
Returns a zipper for nested sequences, given a root sequence