Fork me on GitHub
#core-async
<
2021-05-25
>
Ben Sless06:05:57

is there some convenient way to macro expand go blocks? Can't figure out how to propagate the env correctly

raspasov06:05:24

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))))

Ben Sless06:05:09

Now try binding a channel outside the go block

Joshua Suskalo14:05:18

There's macroexpand-all from clojure.walk

noisesmith16:05:13

> 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

noisesmith16:05:56

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 message

noisesmith16:05:09

I think that's what's going on here at least

Ben Sless18:05:46

Even simpler example

(macroexpand-1 '(a/go (a/<! c)))

Ben Sless18:05:04

go relies on &env