Implement :close options :specified (default until recently, and now again), :balanced (default just prior to this commit), :none (which also removes instructions that open multiple code blocks)
This commit is contained in:
parent
ddb788ad84
commit
70e9f81f84
@ -51,16 +51,30 @@
|
|||||||
"Returns a random instruction from a supplied pool of instructions, evaluating
|
"Returns a random instruction from a supplied pool of instructions, evaluating
|
||||||
ERC-producing functions to a constant literal."
|
ERC-producing functions to a constant literal."
|
||||||
[instructions argmap]
|
[instructions argmap]
|
||||||
(let [instructions (remove #(= % 'close) instructions)
|
(case (:closes argmap)
|
||||||
p (/ (apply + (filter identity
|
:specified (let [instruction (rand-nth instructions)]
|
||||||
(map #(get parentheses/opens %) instructions)))
|
|
||||||
(count instructions))]
|
|
||||||
(if (< (rand) p)
|
|
||||||
'close
|
|
||||||
(let [instruction (rand-nth instructions)]
|
|
||||||
(if (fn? instruction)
|
(if (fn? instruction)
|
||||||
(instruction)
|
(instruction)
|
||||||
instruction)))))
|
instruction))
|
||||||
|
:balanced (let [source (remove #(= % 'close) instructions)
|
||||||
|
p (/ (apply + (filter identity
|
||||||
|
(map #(get parentheses/opens %) source)))
|
||||||
|
(count source))]
|
||||||
|
(if (< (rand) p)
|
||||||
|
'close
|
||||||
|
(let [instruction (rand-nth source)]
|
||||||
|
(if (fn? instruction)
|
||||||
|
(instruction)
|
||||||
|
instruction))))
|
||||||
|
:none (let [multi-block-instructions (set (filter (fn [i]
|
||||||
|
(let [opens (get parentheses/opens i)]
|
||||||
|
(and opens (> opens 1))))
|
||||||
|
instructions))
|
||||||
|
source (remove (set (conj multi-block-instructions 'close)) instructions)
|
||||||
|
instruction (rand-nth source)]
|
||||||
|
(if (fn? instruction)
|
||||||
|
(instruction)
|
||||||
|
instruction))))
|
||||||
|
|
||||||
(defn count-points
|
(defn count-points
|
||||||
"Returns the number of points in tree, where each atom and each pair of parentheses
|
"Returns the number of points in tree, where each atom and each pair of parentheses
|
||||||
|
Loading…
x
Reference in New Issue
Block a user