jank development update - Syntax quoting!

submited by
Style Pass
2024-03-29 20:00:06

Oh, hey folks. I was just wrapping up this macro I was writing. One moment.(defmacro if-some [bindings then else] (assert-macro-args (vector? bindings) "a vector for its binding" (= 2 (count bindings)) "exactly 2 forms in binding vector") (let [form (get bindings 0) pred (get bindings 1)] `(let [temp# ~pred] (if (nil? temp#) ~else (let [~form temp#] ~then)))))

"Does all of that work in jank?" I hear you asking yourself. Yes! Indeed it does. Since my last update, which added dynamic bindings, meta hints, and initial reader macros, I've finished up syntax quoting support, including gensym support, unquoting, and unquote splicing. We might as well see all of this working in jank's REPL CLI.❯ jank repl > (defmacro if-some [bindings then else] (assert-macro-args (vector? bindings) "a vector for its binding" (= 2 (count bindings)) "exactly 2 forms in binding vector") (let [form (get bindings 0) pred (get bindings 1)] `(let [temp# ~pred] (if (nil? temp#) ~else (let [~form temp#] ~then))))) #'clojure.core/if-some > (if-some [x 123] (str "some " x) "none") "some 123" > (if-some [x nil] (str "some " x) "none") "none" >New interpolation syntax

Leave a Comment