The problem is that I loaded the structs in LoadTemplates and now I am using a generic function from ContentGen that dispatches on those structs.
How is this usually solved? I guess I can “unmodulate” my Julia files. Or maybe there’s a way to chop off all those Main.Poetry... to get just TicketTemplates.myStruct.
Finally, I’d like to know what’s behind this design decision and what are the use cases.
So the two structs are not the same. I’m guessing you includeed a file defining that struct twice, once in TicketTemplates and once in ContentGen? If so, these two definitions define distinct types, due to being in a different namespace due to being in a different module.
Yes. using/import are for navigating the module hierarchy. include is for establishing that hierarchy (it’s literally pasting the code from the included file where you wrote include). Thus, multiple includes literally create new nodes in the module hierarchy - they are not linked to the original file.
You’re still including that file twice, which will still create two modules. The first module will be the one Load sees and binds to, then in methods.jl you create a newStructs module which is what Methods sees and binds to (and which overwrites the binding created in load.jl).
I don’t know why you’re creating submodules for the structs in particular, I’d just have them defined like so:
poet.jl
module Poet
include("structs.jl")
include("methods.jl")
end
structs.jl
struct myStruct
...
end
modules.jl
function method(strt::myStruct)
"I got called"
end
Thank you for introducing me to the XY-problem name. I knew it but didn’t know it was coined as such
That’s a very real possibility. I am writing a fuzz tester for a C program. I looked around for design patterns but didn’t find any so my current implementation feels sketchy to me.
The fuzz tester simply generates txt files following templates and I vary the fields depending if they are evaluated in branching conditions or not, so that I can better cover the code flow.
Eventually I might drop the structs.jl file for json. But then I’d have to find a better way to match the methods of generic functions.
Maybe I could simply do away with all modules, but that would lead me to my initial annoyance of struct redefinition error