Sleep 10000
does not seem to actually sleep in the REPL. How can I get it to sleep? And which platform is it running? How can I print stuff?
The REPL isn't running a platform.
There are no Effects available
You can read more about it in crates/repl_wasm
https://github.com/roc-lang/roc/tree/main/crates/repl_wasm
Oh, wait your asking about the roc cli REPL not the web REPL.
I think that is in crates/repl_cli
And also doesn't have any Effects
Though I really don't have much familiarity with this part of the codebase
Definitely a little off-topic from your question... but I thought we discussed somewhere an idea that would enable platforms to provide something and enable REPL-like experiences. Like you could have basic-cli provide something, and then when you run roc repl URL/to/platform
or something you could be in a REPL with basic-cli Effects available.
Just a vague recollection, I'm not sure it got seriously discussed or proposed.
Thanks Luke, that's very helpful.
Having effects in the REPL, and ideally being able to choose the platform, that would make the REPL much more useful.
What are you wanting to do with it?
You just reminded me, @Ayaz Hafiz built something that makes it possible to use Roc in a jupyter notebook I thought. I wonder if that is still working? I'd love to add that to roc-awesome if it's something people can easily use.
https://gist.github.com/ayazhafiz/2ecb5d07393421c06fde945784efb384
you also need a branch of the compiler - https://github.com/roc-lang/roc/tree/patch-for-jupyter-kernel
Any reason why we don't just rebase that and merge it so anyone can use env JUPYTER_KERNEL
just from a nightly?
Aurélien Geron said:
Having effects in the REPL, and ideally being able to choose the platform, that would make the REPL much more useful.
Yeah, I think we could make a bespoke basic CLI like platform that was for the repl, but I dont think we could ever make it platform generic. Just due to how platforms work. though I would guess instead of adding effects and platform picking to the repl, it would make more sense to add repls to platforms where they fit. But yeah, something to think about more
@Luke Boswell it's a bit hacky, but feel free to open a PR for it if you think it's worth landing
Maybe Richard's safe scripting idea is just the roc cli/REPL... the Effects can be provided to the REPL, and if you run a roc file without any header it is assumed to be a REPL input.
Luke Boswell said:
What are you wanting to do with it?
Pretty much anything I could do in a Python or Ruby shell, i.e. just like a basic-cli app, I suppose (but I'm still learning Roc, so this might not make any sense)
I think the safe scripting idea would be an alternative version of basic CLI that can run any basic CLI script but will ask before running effects. Probably would be a feature flag on basic CLI that gets released. So it always has the exact same API and is easy to switch to. I don't think it relates to the repl.
As for repl+ basic CLI....I have no idea how that would be driven or state would be stored, but theoretically, basic CLI could run in a repl mode where it compiles code as shared libraries and runs them.....but no idea how state would function. This is where a roc interpreter would be exceptionally helpful.
And we've talked about needing an interpreter using the dev backends anyway for comptime calculation of constants.
I don't think it would use the dev backend. I think it would be a standalone think that walks one of the irs.
Maybe converts it once into a more execution friendly form
We talk about using the dev backend for this, but it has a lot of complication that an interpreter wouldn't
I think it would be nice to have a repl for the basic-webserver platform. Running the platform makes no sense without a main function. The only solution i see is platforms providing default implementation and an ability to swap it out with a new repl defined function.
For basic webserver? I'm not sure I follow how that would be expected to work in general. Would it give you a request and expect you to write the handler directly in the repl?
at the start of the repl I would probably have to provide a main function to the platform
Ok, but after that how do you interact with it?
Oh I see the problem. I imagined i could replace the current main function dynamically.
Sounds more like hot code reloading than a repl
Which I assume basic webserver could support
I see... Perhaps i'm misusing repls. Could you please quickly point out the usage of basic-cli in a repl?
With basic CLI (if we build a proper repl that can pause for it), it is generally a single flow of execution. So it would just interrupt after each roc command and wait for more code. It just needs to a way to store roc state and continue execution. I think that could make sense. You might do something totally one off with this (this would be like how most people use python repl or like an interactive terminal session)
Basic webserver is different because it runs multithreaded and only maps a request to a response. I don't think it has a clean separation for repl work. On top of that, it doesn't really make sense to do something one off. Instead you may just want to play with various different request handlers. Probably actually want hot code reloading where when you would make a new request handler and save, then the webserver swaps any new requests over to that instead.
Oh I see. I was sort of trying to achieve dropping from a live system into a sort of debugger. Perhaps repl isn't the most appropriate place for this
Ah
Yeah, I see.
You could use something like gdb, lldb, or any debugger that supports compiled languages like c/c++/rust. But our debug info is especially limited and I would not expect it to go well.
We don't have any sort of interactive experience for what you want to do.
I think the best way today is dbg statements and running through code
That was the workflow i adopted, perhaps it would work even better with hot reloading. Maybe I've gone too far off topic. So TLDR: Only some platforms can support the Repl. Default implementations of platform provided functions not yet necessary.
Last updated: Jul 06 2025 at 12:14 UTC