Fork me on GitHub
#clojurescript
<
2019-05-11
>
ag02:05:40

Can someone help me out with a macro callable from Clojurescript? https://clojureverse.org/t/help-me-with-a-clojurescript-macro/4249

arbscht03:05:52

note macro arguments don't get evaluated

arbscht03:05:21

play around with macroexpand-1 to see what your macro gets expanded into in the two cases

ag03:05:29

so how do I get them evaluated?

arbscht03:05:07

evaluation happens at runtime, you can evaluate arguments with a function call, for example

arbscht03:05:27

otherwise you'd need eval, but you're in cljs

arbscht03:05:51

it looks like you're trying to generate code at macroexpansion time for a runtime value

arbscht03:05:06

I can't see how that could work

ag03:05:09

oh… I see

ag03:05:31

that’d be sad if I can’t do it

arbscht03:05:39

let me take a step back

arbscht03:05:55

are you trying to reduce the boilerplate necessary to generate material-ui bindings?

arbscht03:05:55

I wonder if it's good enough to do codegen the old fashioned way. discover your MaterialUI keys in an earlier build step, then serialize it to a file such that you are invoking your macro with a literal argument

ag03:05:27

¯\(ツ)

ag03:05:08

why can’t I somehow loop through (js/Object.keys js/MaterialUI) in a macro?

arbscht03:05:19

you can, if you know the value of js/MaterialUI at macroexpansion time

arbscht03:05:34

getting the value through an argument to the macro delays its evaluation so you don't know it

ag03:05:54

so I have to do it in the macro

ag03:05:35

I’m trying to figure out how to loop in a macro… I looked how doseq is done… and… that’s some scary shit

arbscht03:05:42

here's an example derived from your post

ag03:05:53

wow, thanks… I’ll study it

arbscht03:05:12

(tags is redundant, try-me doesn't use it)

ag03:05:50

that doesn’t compile though.. it doesn’t know what js is

arbscht04:05:30

right, so it won't be able to find MaterialUI either in that case

arbscht04:05:41

(I'm testing in a repl which has js loaded but the compiler won't, of course)

arbscht04:05:08

if you used a clj hash map rather than a #js array, it should work

ag04:05:28

I give up… I’m tired and I can’t solve it… even tried using js/eval. I’m missing something here. Will try again later. Thank you for your help @UHBQQMPGR

arbscht04:05:36

sorry I can't be of more help this time, also a bit distracted myself. the macro-eval-compile triad in cljs is a tricky beast

ag04:05:44

You helped me It is tricky indeed, but I intend to solve this puzzle.

arbscht04:05:49

fwiw, I'm using material in a project too, and have gone with the codegen route I suggested earlier

arbscht04:05:26

it's not very neat though, I can see the temptation to do it dynamically in one pass

ag04:05:44

It might turn to be unsolvable. Whatever I come up with if it doesn't pass advanced compilation is useless anyway

polymeris19:05:06

(s/def ::my-ch #(instance? cljs.core.async.impl.channels/ManyToManyChannel %))
Is there a better way to write a chan? predicate for specs? I.e. without reaching into impl?

borkdude20:05:55

where is defn defined in CLJS? I can’t find it in core.cljc. Is it a compiler special case?

thheller20:05:34

its a macro so should be in there

borkdude20:05:07

thanks 🙂

borkdude21:05:57

what about the ns macro?

thheller21:05:25

thats not a macro in CLJS. look for parse 'ns in cljs.analyzer