clojush.util

all-items

(all-items lst)

Returns a list of all of the items in lst, where sublists and atoms all count as items. Will contain duplicates if there are duplicates in lst. Recursion in implementation could be improved.

average

(average & args)

code-at-point

(code-at-point tree point-index)

Returns a subtree of tree indexed by point-index in a depth first traversal.

compute-next-row

(compute-next-row prev-row current-element other-seq pred)

computes the next row using the prev-row current-element and the other seq

containing-subtree

(containing-subtree tree subtree)

If tree contains subtree at any level then this returns the smallest subtree of tree that contains but is not equal to the first instance of subtree. For example, (contining-subtree ‘(b (c (a)) (d (a))) ’(a)) => (c (a)). Returns nil if tree does not contain subtree.

contains-subtree

(contains-subtree tree subtree)

Returns true if tree contains subtree at any level. Inefficient but functional implementation.

count-parens

(count-parens tree)

Returns the number of paren pairs in tree

count-points

(count-points tree)

Returns the number of points in tree, where each atom and each pair of parentheses counts as a point.

debug-recent-instructions

ensure-list

(ensure-list thing)

hamming-distance

(hamming-distance seq1 seq2)

Calculates the Hamming distance between two sequences, including strings

insert-code-at-point

(insert-code-at-point tree point-index new-subtree)

Returns a copy of tree with the subtree formerly indexed by point-index (in a depth-first traversal) replaced by new-subtree.

keep-number-reasonable

(keep-number-reasonable n)

Returns a version of n that obeys limit parameters.

levenshtein-distance

(levenshtein-distance a b & {p :predicate, :or {p =}})

Levenshtein Distance - http://en.wikipedia.org/wiki/Levenshtein_distance In information theory and computer science, the Levenshtein distance is a metric for measuring the amount of difference between two sequences. This is a functional implementation of the levenshtein edit distance with as little mutability as possible. Still maintains the O(n*m) guarantee.

list-to-open-close-sequence

(list-to-open-close-sequence lst)

literals

mean

(mean coll)

median

(median coll)

not-lazy

(not-lazy lst)

Returns lst if it is not a list, or a non-lazy version of lst if it is.

open-close-sequence-to-list

(open-close-sequence-to-list sequence)

postwalklist

(postwalklist f form)

Like postwalk, but only for lists

postwalklist-replace

(postwalklist-replace smap form)

Like postwalk-replace, but only for lists.

prewalkseq

(prewalkseq f s)

Like prewalk but only for seqs and uses zippers.

print-return

(print-return thing)

Prints the provided thing and returns it.

recognize-literal

(recognize-literal thing)

If thing is a literal, return its type – otherwise return false.

remove-code-at-point

(remove-code-at-point tree point-index)

Returns a copy of tree with the subtree formerly indexed by point-index (in a depth-first traversal) removed. The old version would not allow removals that result in empty lists, but the current version allows this behavior.

round-to-n-decimal-places

(round-to-n-decimal-places f n)

If a number, rounds float f to n decimal places.

seq-zip

added in 1.0

(seq-zip root)

Returns a zipper for nested sequences, given a root sequence

sequence-similarity

(sequence-similarity sequence1 sequence2)

subst

(subst this that lst)

Returns the given list but with all instances of that (at any depth)
replaced with this. Read as ‘subst this for that in list’.

test-and-train-data-from-domains

(test-and-train-data-from-domains domains)

Takes a list of domains and creates a set of (random) train inputs and a set of test inputs based on the domains. Returns [train test]. A program should not be considered a solution unless it is perfect on both the train and test cases.

truncate

(truncate n)

Returns a truncated integer version of n.

walklist

(walklist inner outer form)

Like walk, but only for lists.