Why does the REPL work in Main?

question

#1

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

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.


#3

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


#4

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


#5

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


#6

Yes, that would certainly be a nice feature.


#7

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


#8

#9

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


#10

That would be great.


#11

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