Creating a variable with a macro, and then use it in its body

yes! And this is exactly what I’m doing right now.

But this approach do not work perfectly for me for two reasons:

  • I need to define multiple rows in a single module (and right now I’m using the fields attribute and then wipe it right after the macro body invocation to be empty for the next row)

  • the fact that you are not forced in any way to use field inside a row macro, so weird things could happen. But maybe this is also a problem for ecto…and with a good documentation should be ok.

I’d really love to create a struct in the row macro and than pass it (like var!) when unquoting the body, but as far as I know it’s impossible…

2 Likes