Make plushy->push obey :diploid setting

This commit is contained in:
Lee Spector 2020-11-22 16:19:24 -05:00
parent 4516339412
commit 12002d17a6

View File

@ -12,7 +12,8 @@
(defn plushy->push
"Returns the Push program expressed by the given plushy representation."
[plushy argmap]
(let [opener? #(and (vector? %) (= (first %) 'open))] ;; [open <n>] marks opens
(let [plushy (if (:diploid argmap) (map first (partition 2 plushy)) plushy)
opener? #(and (vector? %) (= (first %) 'open))] ;; [open <n>] marks opens
(loop [push () ;; iteratively build the Push program from the plushy
plushy (mapcat #(if-let [n (get push/opens %)] [% ['open n]] [%]) plushy)]
(if (empty? plushy) ;; maybe we're done?