I was playing with code that generates a struct + accompanying code, based on a set of information that can be represented with groups of symbols. It occurred to me that I could simplify the syntax around this stuff if I could do something like, for example:
@generated struct MyStruct{A::Symbol, B::Tuple, C}
fields = collect(:($(esc(param))::C) for param in B.parameters)
constructors = begin [do some stuff with A and C] end
return quote
$fields
$constructors
end
end
Is there anything like this in Julia? And if not, is there a good reason, or is it just an idea nobody has gotten to? I don’t really understand the inner workings of @generated functions yet.