Move the submodule to the top. The top-level forms of the outer modules are processed in order, meaning when Racket gets to (require ‘bar) it hasn’t seen (module bar …) yet.
If I move it to the top then it works in DrRacket for this small example.
I could not find anywhere in the official docs that there is a requirement that submodules must be defined before they are required. Did I miss it or is it undocumented?
I also am trying to use submodules in a bigger project where I have lots of actual .rkt files. In 1 of the files I am trying to use submodules:
I think we need more context to explain this error. When I comment out the collects and filed I don’t have, I get generate-data-entities not defined, as expected.
Thanks, I dug a little deeper and narrowed the error I am getting to the import:
sunshine-fw/sourcecode/code/oo/ast/builder
That module exports an identifier called module which interfered with the Racket module form.
If I import that module as prefixed, then my errors go away.
Now the only thing I am still wondering is the requirement that a module must be defined before it is required. I would like the submodules at the bottom of the file not the top really. Is there no way to do this using the (module) form?
A require form not only introduces bindings at expansion time, but also visits the referenced module when it is encountered by the expander.
In other words, the expander will attempt to locate the module's code as soon as it hits the require clause.
Put another way, imports aren't "delayed" until after expansion, they happen on the go. module clauses work similarly, which is why you can require a module that's declared previously in the same file.
That explanation is not as straight forward for new devs learning Racket. I think it would be beneficial to update the Racket Guide or Racket Reference to actually state this explicitly.
I will update my own Racket book with a more explicit explanation of define-a-module-before-requiring-it behaviour
I will go with putting the submodules at the top as this seems to be per-design of Racket.
Thanks for everyone who put me on the right path.
Always a pleasure to be part of the Racket community.