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?
I don't think its you, if I remember correctly the stuff in the arg parser module has some issues.
Ahhh yeah here is the issue.
Ah, bummer. Thanks!
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!
seems like the actual issue is https://github.com/roc-lang/roc/issues/5701
if folks think this will be fixed before Advent of Code starts
Probably not, sadly.
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
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.
so that all of my puzzles can be part of the same application. it's how i've done it for haskell and ocaml.
i suppose i could just have a program per day
or maybe this is my year of ocaml and next year is my year of roc :)
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.
@Brendan Hansknecht fair point. does the nested lambdas issue also become a problem for parser combinator style parsing of the input?
i feel like all i need to start aoc is some parser combinator library and some arg parsing library. oh, and sum types ;)
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
I think it can affect parser combinator style parsers.
:cry: got it, so maybe next year for me. i'm super excited about the language
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
thanks!
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.
interesting. is lazy effectively a fixed point combinator?
ah, i see it here, thanks. https://github.com/lukewilliamboswell/roc-parser/blob/46ab6e2a8c13f69601ad516520981331c6b7ce3b/package/Core.roc#L231-L234
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.
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"
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
you specify the version in the URL you use...
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
I would assume the latest nightly release of Roc and that version of basic-cli (the latest) would be compatible.
The "pre-release" one is for the new Roc compiler written in Zig -- which isn't compatible with Weaver
I think this is the release of Roc you would want https://github.com/roc-lang/roc/releases/tag/alpha4-rolling
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.
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.
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
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