Coming from a beginner myself, as far as I can tell: technically yes, but you would still need to at least create an array holding the event argument identifiers, something like:
var args: Array<Expr> = [for (arg in eventArguments) macro $i{arg.name}];
The line in question could then be replaced with:
event = new $className($a{args});
But you lose the Position information, which is invaluable to debugging. Again, I just started learning about macros today myself, so chances are I got something wrong or forgot about something…
It seems it does not work. As I understand it, the reification syntax can only be used for very simple expressions and for something more serious, you should in any case use the creation of structures from the haxe.macro package. I mistakenly adopted the reification syntax for something like string interpolation, but it has much more limitations. We cannot even read values from nested structures. I also tried to generate a class with fields from a string, but again I failed.
Thanks, this example has helped me to understand something. But initially I wanted the code
public static macro function test() : Expr {
var classTypePath : TypePath = {
name : "MyClass",
pack : []
}
var args = [(macro 1), (macro "hi")];
return macro new $classTypePath($a{args});
}
would look something like this
public static macro function test(infos:MacroInfos) : Expr {
return macro new ${infos.path}($a{[for (arg in infos.argumentsData) getArg(arg)]});
}
It’s just that even for such a simple example, you have to declare a whole bunch of variables that are used only once. And we cannot even place them in some kind of structure in order to at least somehow group the data. It turns out that the classic way of creating expressions can be more compact and readable than reification.