Why does the REPL work in Main?



This is really just a question for my curiosity. Why does the Julia REPL work in the Main module, the same module that packages are loaded in, instead of a separate module? Is it because of the convenience of accessing modules that have been loaded from other modules, for, say, debugging purposes?


The real question is why are packages loaded in Main instead of somewhere else – since Main by definition is “where code is evaluated in a script or the repl”. We initially loaded packages in a module called Root, but having Core, Base, Main and Root seemed like too many things, so IIRC, I convinced @jeff.bezanson to just load packages in Main instead and do away with Root altogether. I now think this was a mistake.


I am wondering if the semantics of the language would allow to have a “current” package as a state (similar to, say, Common Lisp), which the user could change, so that whatever happens in the REPL would be evaluated there. This would allow much more interactive development of modules (which has both costs and benefits, to be sure).

One can of course emulate this with eval(SomeModule, expr).


Isn’t that what Juno does with ‘working modules’?


Yes. I am also emulating that in Emacs the same way. But having it integrated into the REPL would be nice.


Yes, that would certainly be a nice feature.


Ref https://github.com/sglyon/REPLMods.jl



Thanks for the ref @kristoffer.carlsson

@StefanKarpinski is there still interest in getting that into base? I could try to find time to hack that in if so


That would be great.


Yes, I think that would be great to have in Base. Probably want to have an API discussion first though.