Simplify and reduce diffs with master

This commit is contained in:
Pietro Cerutti
2026-08-28 19:10:29 +00:00
parent f39447a4ee
commit 8fb4c4f49d
+20 -25
View File
@@ -451,38 +451,33 @@
the `fal` form. Bindings have the same syntax as the `let` macro,
are initially bound to `nil`, and are in scope in both branches.``
[bindings tru &opt fal]
(def len (/ (length bindings) 2))
(def len (length bindings))
(if (= 0 len) (error "expected at least 1 binding"))
(if-not (int? len) (error "expected an even number of bindings"))
(if (odd? len) (error "expected an even number of bindings"))
(def fal2 (if macexvar (macexvar fal) fal))
(def syms (array/new len))
(defn fill-syms [i]
(when (< i len)
(let [bl (in bindings (* i 2))
sym (if (symbol? bl) bl (gensym))]
(put syms i sym))
(fill-syms (+ 1 i))))
(defn aux [i]
(def syms (array/new (/ len 2)))
(defn make-ifs [i]
(if (>= i len)
tru
(do
(def bl (in bindings (* 2 i)))
(def br (in bindings (+ 1 (* 2 i))))
(def bl (in bindings i))
(def br (in bindings (+ 1 i)))
(if (symbol? bl)
~(if (def ,bl ,br) ,(aux (+ 1 i)) ,fal2)
(do
(def sym (in syms i))
~(do (def ,sym ,br) (if (def ,bl ,sym) ,(aux (+ 1 i)) ,fal2)))))))
(defn wrap [i]
(if (>= i len)
(aux 0)
~(do
(def ,(in syms i) ,nil)
,(wrap (+ 1 i)))))
~(if (def ,bl ,br) ,(make-ifs (+ 2 i)) ,fal2)
~(if (def ,(def sym (in syms (/ i 2))) ,br)
(do (def ,bl ,sym) ,(make-ifs (+ 2 i)))
,fal2)))))
(fill-syms 0)
(wrap 0))
(defn make-defs [i]
(if (>= i len)
(make-ifs 0)
~(do
,(let [bl (in bindings i) sym (if (symbol? bl) bl (gensym))]
(put syms (/ i 2) sym)
~(def ,sym ,nil))
,(make-defs (+ 2 i)))))
(make-defs 0))
(defmacro when-with
``Similar to with, but if binding is false or nil, returns