JacquesCarette / Drasil

Generate all the things (focusing on research software)
https://jacquescarette.github.io/Drasil
BSD 2-Clause "Simplified" License
141 stars 26 forks source link

Understanding `buildModule` #3741

Closed B-rando1 closed 4 months ago

B-rando1 commented 4 months ago

I'm implementing methods of the Julia renderer typeclasses in the order that undefined runtime errors appear 😄, and the current one is buildModule. I can't quite seem to get through the syntax and figure out what it's actually doing, could someone help me understand?

The typeclass definition is as follows: https://github.com/JacquesCarette/Drasil/blob/e974d5af2f0f4e2433b5066aeed4d17499766557/code/drasil-gool/lib/GOOL/Drasil/ClassInterface.hs#L635-L637

Here are the current implementations: https://github.com/JacquesCarette/Drasil/blob/e974d5af2f0f4e2433b5066aeed4d17499766557/code/drasil-gool/lib/GOOL/Drasil/LanguageRenderer/SwiftRenderer.hs#L720-L735

https://github.com/JacquesCarette/Drasil/blob/e974d5af2f0f4e2433b5066aeed4d17499766557/code/drasil-gool/lib/GOOL/Drasil/LanguageRenderer/PythonRenderer.hs#L708-L720

https://github.com/JacquesCarette/Drasil/blob/e974d5af2f0f4e2433b5066aeed4d17499766557/code/drasil-gool/lib/GOOL/Drasil/LanguageRenderer/CommonPseudoOO.hs#L142-L153

https://github.com/JacquesCarette/Drasil/blob/e974d5af2f0f4e2433b5066aeed4d17499766557/code/drasil-gool/lib/GOOL/Drasil/LanguageRenderer/CommonPseudoOO.hs#L217-L227

I'd appreciate some help in understanding the code, so that I can write a correct implementation for Julia. Thanks!

JacquesCarette commented 4 months ago

If you look at the 'heart' of the implementation for each, you'll see that it is all vcat and the like -- these are printing (or rendering) commands. So what each of these things is doing is "printing out" the stuff that make up a 'module' in each language.

If you think of a module as sitting in a single file (which is often the case for many languages), then this is the needed imports and other "outer declarations" needed to create somewhere for the 'actual code' to go.

If you pick one file for each language and take a look at what appears before there is any real code (including class declarations), you'll be able to map things closer to the code.

If my memory serves me right, Julia is Python-like enough that that's probably a decent 'template'. [But I could be wrong there!]

B-rando1 commented 4 months ago

I think that makes sense, thanks! I'll give that a go tomorrow, and let you know if I have any more questions.