Stream: beginners

Topic: command line parsing


view this post on Zulip drew (Oct 19 2023 at 15:25):

Hi folks. I'm trying to test out command line parsing from the basic-cli platform, but I'm getting a thread panic. My code and output are here -- https://gist.github.com/drewolson/bef70f973c04e22e4ffe9ec44b9af135. What am I doing wrong?

view this post on Zulip Erik (Oct 19 2023 at 15:56):

I don't think its you, if I remember correctly the stuff in the arg parser module has some issues.

view this post on Zulip Erik (Oct 19 2023 at 15:58):

Ahhh yeah here is the issue.

view this post on Zulip drew (Oct 19 2023 at 16:02):

Ah, bummer. Thanks!

view this post on Zulip drew (Nov 20 2023 at 22:45):

i'm curious if folks think this will be fixed before Advent of Code starts. with the new website release and advent of code just around the corner, i'm sure folks will be trying out roc, and command line arg parsing seems like it would be super useful!

view this post on Zulip drew (Nov 20 2023 at 22:45):

seems like the actual issue is https://github.com/roc-lang/roc/issues/5701

view this post on Zulip Brendan Hansknecht (Nov 20 2023 at 22:49):

if folks think this will be fixed before Advent of Code starts

Probably not, sadly.

view this post on Zulip Elias Mulhall (Nov 20 2023 at 22:50):

Ah I see, you're writing a script to fetch AoC puzzles. The website examples include an example of CLI parsing that gets around this issue, but is a bit noisier https://www.roc-lang.org/examples/CommandLineArgs/README.html

view this post on Zulip drew (Nov 20 2023 at 22:51):

It's not even a script to fetch the puzzles, rather just accepting args from the user as to the day of the puzzle and the part to run.

view this post on Zulip drew (Nov 20 2023 at 22:51):

so that all of my puzzles can be part of the same application. it's how i've done it for haskell and ocaml.

view this post on Zulip drew (Nov 20 2023 at 22:52):

i suppose i could just have a program per day

view this post on Zulip drew (Nov 20 2023 at 22:52):

or maybe this is my year of ocaml and next year is my year of roc :)

view this post on Zulip Brendan Hansknecht (Nov 20 2023 at 22:52):

Also, you can always directly work with args <- Arg.list |> Task.await. The bug is in the nested lambdas used for handling parsing. For AOC, naive parsing probably is enough with just directly using that list of strings.

view this post on Zulip drew (Nov 20 2023 at 22:53):

@Brendan Hansknecht fair point. does the nested lambdas issue also become a problem for parser combinator style parsing of the input?

view this post on Zulip drew (Nov 20 2023 at 22:53):

i feel like all i need to start aoc is some parser combinator library and some arg parsing library. oh, and sum types ;)

view this post on Zulip Agus Zubiaga (Nov 20 2023 at 22:53):

In case it helps anyone, I wrote this poor man's version of the arg parser while I was updating roc-pg to the latest basic-cli the other day: https://github.com/agu-z/roc-pg/blob/72f5390db26527bc3b6067f77ea570f895ff3c0b/sql-cli/src/roc-sql.roc#L191-L278

view this post on Zulip Brendan Hansknecht (Nov 20 2023 at 22:54):

I think it can affect parser combinator style parsers.

view this post on Zulip drew (Nov 20 2023 at 22:54):

:cry: got it, so maybe next year for me. i'm super excited about the language

view this post on Zulip Elias Mulhall (Nov 20 2023 at 22:54):

or maybe this is my year of ocaml and next year is my year of roc :)

fair, they are similar languages and I love OCaml

does the nested lambdas also become a problem for parser combinator style parsing of the input?

Last month I worked through some AoC puzzles in Roc and mostly used parser combinators for parsing. You can see my code here https://github.com/mulias/roctoberfest/tree/main/advent_2022

view this post on Zulip drew (Nov 20 2023 at 22:55):

thanks!

view this post on Zulip Elias Mulhall (Nov 20 2023 at 22:58):

The one type system issue I ran into with parser combinators was a case where I needed a lazy parser to parse recursive data. @Agus Zubiaga showed me a workaround, which is here https://github.com/mulias/roctoberfest/blob/main/advent_2022/day_07/main.roc#L158
You need to use buildPrimitiveParser to "reset" something with the type system. Sorry I can't be more exact than that, it's definitely a hack to get around a bug.

view this post on Zulip drew (Nov 20 2023 at 22:59):

interesting. is lazy effectively a fixed point combinator?

view this post on Zulip drew (Nov 20 2023 at 23:02):

ah, i see it here, thanks. https://github.com/lukewilliamboswell/roc-parser/blob/46ab6e2a8c13f69601ad516520981331c6b7ce3b/package/Core.roc#L231-L234

view this post on Zulip Elias Mulhall (Nov 20 2023 at 23:04):

In general I wouldn't hesitate to use Roc for AoC if you're willing to ask for help around here. It's mostly smooth sailing, but every once in a while you run into a road block where it seems like you're doing the right thing and it's not working. Sometimes that's because you are doing the right thing and the compiler has a bug.

view this post on Zulip Plas (Feb 26 2026 at 04:18):

Hi, I'm new to the language and ecosystem.

Does anyone have a recommendation on command line parsing? I thought 'weaver' to be the de-facto standard, but I couldn't get it to work, the examples don't compile. I think it might be because of version mismatch with basic cli platform, or the roc version itself.

Also, are there any schemes to indicate dependency version? "my package relies on specific version of basic cli platform"

view this post on Zulip Luke Boswell (Feb 26 2026 at 04:38):

Yeah I would have thought Weaver was the way to go. I haven't tried using it in a while it may need a minor update

view this post on Zulip Luke Boswell (Feb 26 2026 at 04:39):

you specify the version in the URL you use...

view this post on Zulip Luke Boswell (Feb 26 2026 at 04:39):

e.g.

app [main!] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.20.0/X73hGh05nNTkDHU06FHC0YfFaQB1pimX7gncRcao5mU.tar.br" }

refers to version 0.20.0 of basic-cli

view this post on Zulip Luke Boswell (Feb 26 2026 at 04:40):

I would assume the latest nightly release of Roc and that version of basic-cli (the latest) would be compatible.

view this post on Zulip Luke Boswell (Feb 26 2026 at 04:40):

The "pre-release" one is for the new Roc compiler written in Zig -- which isn't compatible with Weaver

view this post on Zulip Luke Boswell (Feb 26 2026 at 04:41):

I think this is the release of Roc you would want https://github.com/roc-lang/roc/releases/tag/alpha4-rolling

view this post on Zulip Luke Boswell (Feb 26 2026 at 04:42):

If you want to try out the new Roc compiler (re-write in Zig) -- there are releases available at https://github.com/roc-lang/nightlies/releases -- but be warned there is basically no platforms or packages available to use with them yet, so it's not a friendly beginner experience.

view this post on Zulip Norbert Hajagos (Feb 26 2026 at 07:38):

I don't know how weaver works, but there shouldn't be that big of a dependence on platforms in packages. By that, I mean weaver probably takes a value (string or list of strings) and does the parsing. It's not like a go or js package where the package is also responsible for obtaining the values. If this is the case, even if there is a slight missmatch in the api, you as the app author should be able to make a simple transformation on the data, before you hand it over to weaver.
Or if it takes an effectul function, it's easy to wrap the efectul basic-cli fn and do the transformation there. Just saying it, becasue I don't know how familiar you are with Roc.
As Luke's said, at this stage, language version missmatches are the main incompatibility issue. But this is a temporary state.

view this post on Zulip Plas (Feb 26 2026 at 10:55):

I'm kind of away now but iirc the failure probably was due to changes in Str or Result type

I am very very new to Roc, I get that the project still changes a lot. I just wish people wouldn't put "latest version of basic cli" in their projects, and rather specify exact roc version and basic cli version they tested with, until roc hits 1.0.0

view this post on Zulip Anton (Feb 27 2026 at 10:10):

The examples repo has exact versions specified: https://github.com/roc-lang/examples/blob/main/examples/CommandLineArgs/main.roc

Everything in the examples repo uses roc alpha4.

We also plan to specify the Roc version in the .roc file to avoid all these version incompatibility issues.


Last updated: Mar 20 2026 at 12:28 UTC