Stream: beginners

Topic: How do I read many stdin lines with new compiler platform?


view this post on Zulip Artem (Jan 04 2026 at 19:58):

I tried to create a small util that would read unknown beforehand amount of lines from stdin. It reads, checks that the line is not a stop marker, and adds a line to a list.

Not only was it agonizingly slow (about 470 lines per second), but it ran out of stack memory on line 3330.

Was something wrong with my implementation?

Here is my code:

app [main!] { pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.6/2BfGn4M9uWJNhDVeMghGeXNVDFijMfPsmmVeo6M4QjKX.tar.zst" }

import pf.Stdout

read_stdin_until! : Str, List(Str) => List(Str)
read_stdin_until! = |break_str, buffer| {
    new_line = Stdin.line!()
    if new_line == break_str {
        buffer
    } else {
        read_stdin_until!(break_str, buffer.append(new_line))
    }
}

Run result: Roc crashed: This Roc program overflowed its stack memory. This usually means there is infinite recursion somewhere in the code.

P.S. The file that I piped into my Roc app was small: about 25 Kb in total, ~4500 lines with 3-5 chars

view this post on Zulip Brendan Hansknecht (Jan 04 2026 at 21:05):

Probably an interpretter bug in my opinion.

view this post on Zulip Brendan Hansknecht (Jan 04 2026 at 21:05):

The interpretter needs to be smart enough to do tail call optimization and avoid these kinds of stack overflows

view this post on Zulip Luke Boswell (Jan 04 2026 at 21:53):

We dont have any TCO yet I believe

view this post on Zulip Richard Feldman (Jan 04 2026 at 23:01):

yeah TCO has not been ported over yet

view this post on Zulip Richard Feldman (Jan 04 2026 at 23:06):

I would normally start porting it, but I've already hit my Claude Max weekly limit halfway through the week, and rather than get a second account (which I did consider) I'm going to use this as a forcing function to spend my time on langref instead :laughing:

view this post on Zulip Artem (Jan 04 2026 at 23:18):

Do you guys maybe have any ideas on how to smuggle a file into Roc? I don't want to bring it as a list into the source .roc files because it's a matter of principle now.

I assume that old file import syntax doesn't work on new compiler and since platform doesn't have files API, my only option is stdin. Is that correct? At this point I am considering concatenating all input into one huge line :sweat_smile:. Or maybe read it in chunks to avoid stack growth

view this post on Zulip Artem (Jan 04 2026 at 23:20):

But I was curious, of course, about exotic and silly hacks

view this post on Zulip Richard Feldman (Jan 04 2026 at 23:33):

I think the old file import syntax works but I wouldn't swear to it :smile:

view this post on Zulip Richard Feldman (Jan 04 2026 at 23:33):

I'm on mobile but I recommend giving it a try!

view this post on Zulip Luke Boswell (Jan 05 2026 at 00:59):

Yeah I'm pretty sure we haven't implemented the import file stuff yet

view this post on Zulip Luke Boswell (Jan 05 2026 at 00:59):

Btw you can use basic-cli if you're happy to build the platform from source

view this post on Zulip Luke Boswell (Jan 05 2026 at 00:59):

Use this branch https://github.com/roc-lang/basic-cli/pull/413

view this post on Zulip Luke Boswell (Jan 05 2026 at 01:00):

I've just been working through some issues preventing us from completing the other effects, but I think I just solved it -- so hopefully those can migrate now too

view this post on Zulip nandi (Jan 05 2026 at 05:18):

Richard Feldman said:

I would normally start porting it, but I've already hit my Claude Max weekly limit halfway through the week, and rather than get a second account (which I did consider) I'm going to use this as a forcing function to spend my time on langref instead :laughing:

I use opus with copilot because copilot doesn't have usage limits, its not a horrible agent either

view this post on Zulip Luke Boswell (Jan 05 2026 at 05:19):

How does that work? like Opus does the thinking/reasoning and copilot does the tasks?

view this post on Zulip nandi (Jan 05 2026 at 05:21):

yeah it's like claude code but its a copilot binary instead of a claude code binary https://github.com/github/copilot-cli

view this post on Zulip Luke Boswell (Jan 05 2026 at 05:22):

Cool, I'll give that a try when I hit my daily usage limit :smile:

view this post on Zulip nandi (Jan 05 2026 at 05:25):

There is a monthly limit and then they charge you but I've hit the monthly multiple months in a row and it just keeps going without ending I dunno if a bug or what. I'm trying not to publicize it too much in case they decide to fix it heh

image.png

view this post on Zulip nandi (Jan 05 2026 at 05:29):

image.png

view this post on Zulip nandi (Jan 05 2026 at 05:30):

I've got it up to over 400% last month

view this post on Zulip nandi (Jan 05 2026 at 18:49):

turns out their billing UX is just bad, lol got charged 100 bucks for last month usage. Not horrible but still not what I was wanting lol.


Last updated: Jan 12 2026 at 12:19 UTC