core-async

Ben Sless 2021-05-25T06:07:57.004600Z

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

2021-05-25T14:51:18.005200Z

There's macroexpand-all from clojure.walk

2021-05-25T16:26:13.005400Z

> 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

2021-05-25T16:29:56.005600Z

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

2021-05-25T16:30:09.005800Z

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

Ben Sless 2021-05-25T18:09:46.006100Z

Even simpler example

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

Ben Sless 2021-05-25T18:10:04.006300Z

go relies on &env

raspasov 2021-05-25T06:14:24.004700Z

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 Sless 2021-05-25T06:31:09.004900Z

Now try binding a channel outside the go block