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:
Lee Spector 2024-01-12 16:25:59 -05:00
parent ddb788ad84
commit 70e9f81f84

View File

@ -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))) (if (fn? instruction)
(count instructions))] (instruction)
(if (< (rand) p) instruction))
'close :balanced (let [source (remove #(= % 'close) instructions)
(let [instruction (rand-nth instructions)] p (/ (apply + (filter identity
(if (fn? instruction) (map #(get parentheses/opens %) source)))
(instruction) (count source))]
instruction))))) (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