Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/gen/dynamic.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,28 @@
[& args]
{:clj-kondo/lint-as 'clojure.core/fn}
(apply gen-body args))

(defmacro let-traced
"Similar to `clojure.core/let`, but wraps all values in [[trace!]] calls
addressed via the binding symbol.

Example usage:

```clojure
(def func
(gen []
(let-traced [a (gen.distribution/delta \"face\")
b (gen.distribution/delta \"cake\")]
(str a \",\" b))))

(into {} (gf/simulate func []))
;; => {:a \"face\" :b \"cake\"}
```"
[bindings & body]
(let [bents (partition 2 bindings)]
(assert (every? symbol? (map first bents)))
`(let ~(into []
(mapcat (fn [[sym expr]]
[sym `(trace! (quote ~sym) ~@expr)]))
bents)
~@body)))