Hi! 

I'm trying to figure out how to split a module across multiple files. Or 
better put, to have multiple submodules inside a main module, with each 
submodule in one file. However, I always end up with the latest file 
overwriting the module code previously imported (last submodule overwrites 
the previous submodule). 

Example: 

=============

# file: a.jl
module Test

module A

export a

function a()
  println("a")
end

end

end

==============

# file: b.jl

module Test

module B

export b

function b()
  println("b")
end

end

end

===============

Expected result: 
upon including both files in a 3rd file or REPL, Test.A.a() and Test.B.b() 
should both be in scope. 

Actual result: 
last included file overwrites everything in Test, so either Test.A.a() or 
Test.B.b() are in scope, but not both. 

================

Where am I going with this? 
I'm interested in applying a design pattern common in ruby (rails) or 
elixir. In these languages one can split a module (or class/type 
definition) across multiple files and with each inclusion, the 
module/class/type is reopened, and the new methods are appended. 

Why doing this? 
Coming from ruby/elixir, it's an excellent way of organizing a complex 
codebase. I'm coding a web framework and I want all the framework code to 
be in a Framework super-module - with submodules for each major feature, 
like Router, Server, Controller, etc. To encapsulate the framework code in 
a structure like Framework.Router, Framework.Server, etc. 
Then the user app, a instance implementation of the web framework would be 
in a module of it's own, say AppName, with it's own submodules for Routes, 
Config, etc. Resulting in AppName.Routes, AppName.Config, etc. (Similar to 
how rails organizes the apps). 

Is this possible? If yes, how can it be done? 

Many thanks for your time and your help, much appreciated! 

Reply via email to