core: move binding macro to overlay
Phase 3 batch 6 (jolt-1j0). binding installs an array-map var->value thread frame and restores it on exit via try/finally. Dynamic rebinding is seen by called fns. This completes the cleanly-portable safe macros (19 total). conformance 228/228 x3, full suite green.
This commit is contained in:
parent
394bbe07c3
commit
3dafa60e65
3 changed files with 14 additions and 28 deletions
|
|
@ -107,6 +107,15 @@
|
|||
[] fnspecs)]
|
||||
`(let* [~@binds] ~@body)))
|
||||
|
||||
;; Dynamic binding: install a thread-binding frame of var->value (array-map keeps
|
||||
;; var-get happy, unlike a phm), restore on exit.
|
||||
(defmacro binding [bindings & body]
|
||||
(let [pairs (reduce (fn [acc p] (conj (conj acc `(var ~(first p))) (second p)))
|
||||
[] (partition 2 bindings))]
|
||||
`(let* [frame# (array-map ~@pairs)]
|
||||
(push-thread-bindings frame#)
|
||||
(try (do ~@body) (finally (pop-thread-bindings))))))
|
||||
|
||||
;; condp: clauses are test-expr result-expr, or test-expr :>> result-fn (calls
|
||||
;; result-fn on the truthy (pred test-expr value)); a lone trailing expr is the
|
||||
;; default. The recursive emit builds a nested if chain.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue