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.


Last updated: Jul 26 2025 at 12:14 UTC