About module creation


I saw the use of Module() somewhere and it seems an equivalent of module A end

However, it is not documented at all.

Is Module(name) a recommended way to create modules programmatically?

Also, I’d like to know how costly is module creation? Would there be any problem if I create a few thousand small modules in run time?

Are they as cheap as dictionaries?


Macros are preferable. You could do things like A = Module(:A) and then eval(A, :( ... ) ) but that’s not the intended interface.

Cheap for what? Module bindings are stored internally in a symbol -> binding hash table that is “fast”, but there’s some other associated state. If you need a dictionary, better to use a dictionary. That’s not what modules are for.


Ref http://stackoverflow.com/q/41639237/176071 for a little more context. I’d love to hear other solutions, but the problem is presented so abstractly that it’s hard to understand what the actual goal is. As I alluded to in the last paragraph there, using eval is typically a big red flag… and especially so if you’re using it in a place where performance is critical.