Macro to create struct problem

Ok, in that case I think the answer from @ffevotte is what you are looking for. You can put an @eval inside a for loop if the code that you’re generating is repetitive. However, there is a tradeoff. I think for loops with @eval are harder to read than just writing the code out by hand. Also, this kind of thing confuses the VS Code linter, so you won’t get correct linting for other parts of the code that use the generated types and functions. (Maybe that will be fixed in the future, but it seems like a tricky issue to fix in the linter.)

See this section of the manual for a discussion of code generation:

https://docs.julialang.org/en/v1/manual/metaprogramming/#Code-Generation

1 Like