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?

2 Likes

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.

1 Like

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).

1 Like

Isn’t that what Juno does with ‘working modules’?
https://github.com/JunoLab/atom-julia-client/blob/master/manual/workflow.md

1 Like

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

1 Like

Yes, that would certainly be a nice feature.

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

https://github.com/JuliaLang/julia/issues/17997

2 Likes

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

5 Likes

That would be great.

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