Stream: ideas

Topic: cli Cmd API


view this post on Zulip Kilian Vounckx (Jun 16 2025 at 22:39):

In my mind, the Command API needs to be fleshed out for a proper scripting platform. It should at least support piping to other commands and to files. As well as redirecting standard streams. With these possibilities, I would see myself using roc more for small scripts. Now I use it more for medium sized projects

view this post on Zulip Luke Boswell (Jun 17 2025 at 00:44):

@Kilian Vounckx we should totally investigate that using the current basic-cli. If we can understand the requirements better that will be good to have ready when we get to building 0.1.

view this post on Zulip Notification Bot (Jun 17 2025 at 06:25):

A message was moved here from #ideas > cli platform out the box by Anton.

view this post on Zulip Anton (Jun 17 2025 at 06:33):

support piping to other commands and to files

I'm concerned that that would basically make Roc scripts a combination of small bash scripts, making the Roc script no real improvement over bash. I like encouraging handling of the data in Roc with nice error messages, and a couple of expect tests.

view this post on Zulip Anton (Jun 17 2025 at 06:34):

@Kilian Vounckx feel free to clarify the value of piping though

view this post on Zulip Anton (Jun 17 2025 at 06:36):

Relatedly; I'm pretty happy with the style of this script I wrote recently. With Claude it's easy to have all non-trivial functions rigorously tested too.

view this post on Zulip Kilian Vounckx (Jun 17 2025 at 07:34):

I'm on the phone right now, so I'll give an example of a script I couldn't translate to roc later (could be a skill issue).
But yeah piping might not be needed except for really big files. I haven't needed them yet, but I could see some people do.
For me, the problem was more that of capturing the standard streams. Like having the choice to capture stdout to a string (or list of bytes) and piping stderr to the roc program's stdout ord something like that

view this post on Zulip Anton (Jun 17 2025 at 08:28):

Yeah, I can see the use for explicit control over stdout and stderr flow.

view this post on Zulip Kilian Vounckx (Jun 17 2025 at 08:49):

Okay on a laptop now. So the bash script that I couldn't translate was this very basic one:

#!/usr/bin/env bash

clear

roc check app/main.roc
roc run --linker=legacy app/main.roc | sed '/P3/,$!d' | convert ppm:- png:- | viu -

So for context, I was doing the Ray Tracing in One Weekend book, and I wanted a render script. The script is in the root repo, while app/main.roc contains the ray tracing program.

The book includes a progress indicator to show how much of the image you have rendered while it is rendering. So stderr needed to be inherited. But I wanted to capture stdout so I could convert it from ppm to png. As far as I could find out (has been half a year now so could have changed), this was not possible in roc.

If I could do the capture/inherit thing, I would have not used sed, but done that part in roc definitely. I also believe that in the future some kind of image package would make the convert step possible in roc. I would prefer to do as much in roc as possible, but sometimes (for calling the invoking the main program and for viu), you need the Command API.

p.s. viu shows the image in a modern terminal. sed is needed because the roc compiler's output like 'this thing is built' is sent to stdout, not stderr. Different discussion though.

p.p.s. I do the roc check before roc run so that the pipeline doesn't start to run if the program is wrong.

view this post on Zulip Anton (Jun 17 2025 at 08:52):

So stderr needed to be inherited. But I wanted to capture stdout so I could convert it

Yeah, this combination is still not possible with the current API

view this post on Zulip Anton (Jun 17 2025 at 08:53):

We should add the possibility to do that

view this post on Zulip Kilian Vounckx (Jun 17 2025 at 08:55):

I have my master's thesis defense in two weeks, so I can't really spend the time on it now. But I could look into providing something like that afterwards

view this post on Zulip Anton (Jun 17 2025 at 08:57):

That would be great :)
Good luck with your thesis defense!

view this post on Zulip Kilian Vounckx (Jun 17 2025 at 09:00):

Thank you!

view this post on Zulip Tobias (Jun 17 2025 at 21:23):

Unix philosophy whatever, in my experience pipes are not rich enough to write robust code. So while I switch to Python a lot when something outgrows bash, I never use the various libraries that make piping easier.
But I agree that sometimes complete control over the file descriptors inherited by a child is necessary.

view this post on Zulip Kilian Vounckx (Jun 17 2025 at 21:36):

Yeah maybe pipes aren't necessary. But I feel like streams (or readers and writers, or whatever you call them, something lazy) is necessary for reading inputs in chunks. Anyways, I will look at the capture/inherit thing in two weeks and maybe lazy streams come afterwards as they seem more complicated


Last updated: Jun 16 2026 at 16:19 UTC