is there some convenient way to macro expand go blocks? Can't figure out how to propagate the env correctly
There's macroexpand-all from clojure.walk
> Can't figure out how to propagate the env correctly > Now try binding a channel outside the go block what behavior are you seeing? in macro expansion, a binding from outside the block should just show up as opaque
is it this error?
Syntax error macroexpanding >/go at (REPL:1:1).
Could not resolve var: c
this is because go
does some "clever" code rewriting, in my experience it doesn't take much to confuse it
(ins)user=> (require '[clojure.core.async :as >])
nil
(ins)user=> (macroexpand '(let [c (>/chan)] (>/go (let [ret (>/<! (>/go (>/<! c)))] (println ret)))))
(let* [c (>/chan)] (>/go (let [ret (>/<! (>/go (>/<! c)))] (println ret))))
(ins)user=> (require '[clojure.walk :refer [macroexpand-all]])
nil
(ins)user=> (macroexpand-all '(let [c (>/chan)] (>/go (let [ret (>/<! (>/go (>/<! c)))] (println ret)))))
Syntax error macroexpanding >/go at (REPL:1:1).
Could not resolve var: c
*edit: added more context to the error messageI think that's what's going on here at least
Even simpler example
(macroexpand-1 '(a/go (a/<! c)))
go
relies on &env
What do you mean by “convenient”? Regular macroexpand works, but the output is quite…. verbose.
(macroexpand-1
'(clojure.core.async/go
(let [ret (clojure.core.async/<! (clojure.core.async/go :hello))]
(println ret))))
Now try binding a channel outside the go block