Add GHCI :l feature to Crystal REPL

Assume i define some functions in hello.hs, in the ghci, when input :l hello.hs, it will load hello.hs, then i can play with the functions defined in this file. this loop is more efficient than use cry for a static type language.

I remember can do same things use load "hellorb", but we have no equivalent.

So, should i create a feature request issue for this?

Use require

So, AFAIK, i have to put “hello.cr” into “./lib/hello.cr”, right?

And one more question, the :l or load "hello.rb" way will always reload after the “./lib/hello.cr” was changed, this is the key reason we want this feature, but, require instead only load once, right?

Because there’s no point in loading the same code twice in compiled mode.

The main idea I had for the interpreter was being able to more easily debug code. Any other extra features, like an interactive console, work but will be underdeveloped. If someone wants to improve that, feel free to send pull requests. Thanks!

Sorry, i thought we are discussing Crystal’s interpreter?

Right, the interpreter works by compiling the code and then interpreting it. It relies on the Crystal language’s semantic. In Crystal you can’t reload a file, so in the interpreter you can’t reload a file.

Any extra thing you want in the interpreter (reloading files, reopening types while they have already been used, etc.) will require a lot of effort to make it work. So for now they won’t work, and at least I won’t put any effort into that (there’s nobody else working on the interpreter.)

You can think the interpreter is just a different backend for the language. The default backend is LLVM, which compiles to native code. Another backend could be compiling things to C (that doesn’t exist yet.) The interpreter is a backend where code is compiled to bytecode and it’s interpreted. That allows for some nice debugging. But that’s it. There’s no other difference. It’s compiled Crystal with nicer debugging capabilities.