The reason for worlds is because of optimizations. If functions can be defined (and redefined) at arbitrary points (and instantly take effect), then that would limit the possible optimizations that can be made. Therefore, new functions are only made visible to the system (become usable) after hitting toplevel. If you try to call a new function before this, then you get a world error.
In some cases (like if you are writing a REPL), you do actually want to call your newly defined function without hitting toplevel. This can be done by using Base.invokelatest(f, args...)
but it will of course prevent certain optimizations in the scope where f
is called (it can pretty much not be reasoned about at all, so no inlining or inference).