You can do that in Nim in a readable way.
import macros macro genMacro(name: untyped): untyped = result = quote do: macro `name`: untyped = result = quote do: echo "Foo" genMacro(bar) bar # Generate and perform the echo
In one of my projects I use a macro to parse a set of types for fields and generate constructor macros for them.
The generated constructor macro passes through the parameters it's given to the default built-in constructor but does some setup before.
The final generated code is a normal built-in construction without proc calling yet with special fields initialised automatically.
Funny, I did a similar thing! :)
You can do that in Nim in a readable way.
Surprisingly I've actually used this kind of thing!In one of my projects I use a macro to parse a set of types for fields and generate constructor macros for them.
The generated constructor macro passes through the parameters it's given to the default built-in constructor but does some setup before.
The final generated code is a normal built-in construction without proc calling yet with special fields initialised automatically.