I got this weird error message I don't understand:
── UNKNOWN OPERATOR ───────────────────────────────────────────────── day2.roc ─
This looks like an operator, but it's not one I recognize!
25│ [a, b] = parseLine line
^
parseLine = \line ->
parts = Str.graphemes line
a = List.get parts 0 |> unwrap
b = List.get parts 2 |> unwrap
[a, b]
getLineScore = \line ->
[a, b] = parseLine line
me = when a is
"A" -> 1
"B" -> 2
"C" -> 3
other = when b is
"X" -> 1
"Y" -> 2
"Z" -> 3
outcome me other
oh that's fun
the list pattern is parsed as an expression
I don't think we support list destructuring like that?
you can use an explicit when
yeah the pattern is not exhaustive anyway
but I'd guess that [..] = someList
works
which is not useful in any way
I'll make an issue for a nicer error message
Oh, so I need to do
when (parseLine line) is
[a, b] -> [a, b]
_ -> crash "fail"
to get that destructuring? :tear:
Yes, for roc it's a key point to minimize runtime errors. So for that reason we should not allow an "easy to reach for syntax" that can crash.
Reliable apps do not come without sacrifices unfortunately, but I suppose AIs will soon be able to generate most of your error-handling code :p
Well, I know it is actually a good thing. :-) In Advent of Code you know it's throwaway code, but in general it is better to force the user to do the right thing, I guess, although rust sometimes drives me mad :-D
Anton said:
Yes, for roc it's a key point to minimize runtime errors. So for that reason we should not allow an "easy to reach for syntax" that can crash.
case in point, in languages like python it's very common to accidently raise ValueError: not enough values to unpack
or too many values to unpack, ofc
Would this work if you returned a tuple instead of a list? Seems like it should, right? I’m pretty sure this would work with a tag
Last updated: Jul 06 2025 at 12:14 UTC