We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 58486bd commit a52e369Copy full SHA for a52e369
1 file changed
src/gen/dynamic.cljc
@@ -211,3 +211,28 @@
211
[& args]
212
{:clj-kondo/lint-as 'clojure.core/fn}
213
(apply gen-body args))
214
+
215
+(defmacro let-traced
216
+ "Similar to `clojure.core/let`, but wraps all values in [[trace!]] calls
217
+ addressed via the binding symbol.
218
219
+ Example usage:
220
221
+ ```clojure
222
+ (def func
223
+ (gen []
224
+ (let-traced [a (gen.distribution/delta \"face\")
225
+ b (gen.distribution/delta \"cake\")]
226
+ (str a \",\" b))))
227
228
+ (into {} (gf/simulate func []))
229
+ ;; => {:a \"face\" :b \"cake\"}
230
+ ```"
231
+ [bindings & body]
232
+ (let [bents (partition 2 bindings)]
233
+ (assert (every? symbol? (map first bents)))
234
+ `(let ~(into []
235
+ (mapcat (fn [[sym expr]]
236
+ [sym `(trace! (quote ~sym) ~@expr)]))
237
+ bents)
238
+ ~@body)))
0 commit comments