I am trying to write a macro that expands to a let form with destructuring. My problem is that I would like to have a list of characters that are defined in the let form, including those that were obtained by destruturing.
Use case
I am trying to discard this behavior, for example, to check:
(let [a (foo bar) {x :x, y :y, {u :u, v: v :as nested-map} :nested} some-map] (and xy nested-map uv ; testing truthiness (valid-a? a) (valid-x? x) (valid-y? y) (valid-nested? nested-map) (valid-u-and-v? uv) ))
Proposed solution
It would be very nice to achieve this with a kind of and-let macro, which I could name as follows:
(and-let [a (foo bar) {x :x, y :y, {u :u, v: v :as nested-map} :nested} some-map] (valid-a? a) (valid-x? x) (valid-nested? nested-map) (valid-u-and-v? uv))
What am i missing
But I don’t have any way to access the list of characters that are connected in the let form. If I had something like a list-bound-symbols function, I could do it like this:
(defmacro and-let "Expands to an AND close that previouly checks that the values declared in bindings are truthy, followed by the tests." [bindings & tests] (let [bound-symbols (list-bound-symbols bindings) ;; what I'm missing ] `(let ~bindings (and ~@bound-symbols ~@tests ) )))
Has anyone understood how I can do this?
source share