Stream: beginners

Topic: Sleep in REPL


view this post on Zulip Aurélien Geron (Jul 08 2024 at 03:26):

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?

view this post on Zulip Luke Boswell (Jul 08 2024 at 03:26):

The REPL isn't running a platform.

view this post on Zulip Luke Boswell (Jul 08 2024 at 03:27):

There are no Effects available

view this post on Zulip Luke Boswell (Jul 08 2024 at 03:28):

You can read more about it in crates/repl_wasm https://github.com/roc-lang/roc/tree/main/crates/repl_wasm

view this post on Zulip Luke Boswell (Jul 08 2024 at 03:31):

Oh, wait your asking about the roc cli REPL not the web REPL.

view this post on Zulip Luke Boswell (Jul 08 2024 at 03:31):

I think that is in crates/repl_cli

view this post on Zulip Luke Boswell (Jul 08 2024 at 03:32):

And also doesn't have any Effects

view this post on Zulip Luke Boswell (Jul 08 2024 at 03:33):

Though I really don't have much familiarity with this part of the codebase

view this post on Zulip Luke Boswell (Jul 08 2024 at 03:35):

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.

view this post on Zulip Luke Boswell (Jul 08 2024 at 03:36):

Just a vague recollection, I'm not sure it got seriously discussed or proposed.

view this post on Zulip Aurélien Geron (Jul 08 2024 at 03:57):

Thanks Luke, that's very helpful.

view this post on Zulip Aurélien Geron (Jul 08 2024 at 04:01):

Having effects in the REPL, and ideally being able to choose the platform, that would make the REPL much more useful.

view this post on Zulip Luke Boswell (Jul 08 2024 at 04:03):

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.

view this post on Zulip Ayaz Hafiz (Jul 08 2024 at 04:16):

https://gist.github.com/ayazhafiz/2ecb5d07393421c06fde945784efb384

view this post on Zulip Ayaz Hafiz (Jul 08 2024 at 04:16):

you also need a branch of the compiler - https://github.com/roc-lang/roc/tree/patch-for-jupyter-kernel

view this post on Zulip Luke Boswell (Jul 08 2024 at 04:17):

Any reason why we don't just rebase that and merge it so anyone can use env JUPYTER_KERNEL just from a nightly?

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 04:24):

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

view this post on Zulip Ayaz Hafiz (Jul 08 2024 at 04:36):

@Luke Boswell it's a bit hacky, but feel free to open a PR for it if you think it's worth landing

view this post on Zulip Luke Boswell (Jul 08 2024 at 04:44):

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.

view this post on Zulip Aurélien Geron (Jul 08 2024 at 04:59):

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)

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 05:18):

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.

view this post on Zulip Luke Boswell (Jul 08 2024 at 05:19):

And we've talked about needing an interpreter using the dev backends anyway for comptime calculation of constants.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 05:32):

I don't think it would use the dev backend. I think it would be a standalone think that walks one of the irs.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 05:32):

Maybe converts it once into a more execution friendly form

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 05:33):

We talk about using the dev backend for this, but it has a lot of complication that an interpreter wouldn't

view this post on Zulip Adrian (Jul 08 2024 at 14:21):

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.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 15:37):

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?

view this post on Zulip Adrian (Jul 08 2024 at 15:39):

at the start of the repl I would probably have to provide a main function to the platform

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 15:40):

Ok, but after that how do you interact with it?

view this post on Zulip Adrian (Jul 08 2024 at 15:41):

Oh I see the problem. I imagined i could replace the current main function dynamically.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 15:42):

Sounds more like hot code reloading than a repl

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 15:42):

Which I assume basic webserver could support

view this post on Zulip Adrian (Jul 08 2024 at 15:44):

I see... Perhaps i'm misusing repls. Could you please quickly point out the usage of basic-cli in a repl?

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 15:51):

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.

view this post on Zulip Adrian (Jul 08 2024 at 15:53):

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

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 15:58):

Ah

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 15:58):

Yeah, I see.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 15:59):

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.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 15:59):

We don't have any sort of interactive experience for what you want to do.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 16:00):

I think the best way today is dbg statements and running through code

view this post on Zulip Adrian (Jul 08 2024 at 16:10):

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