I'm new to roc and have been attempting some exercism exercises to get familiar with the syntax. I'm struggling to get this code for the isogram exercise to compile:
is_isogram : Str -> Bool
is_isogram = |phrase|
phrase
|> Str.walk_utf8(
List.repeat(0, 26),
|vec, char|
when char is
List.range(0x41, 0x5A) -> List.replace(vec, char - 0x41, (List.get(vec, char - 0x41) ?? 0) + 1).list
List.range(0x61, 0x7A) -> List.replace(vec, char - 0x61, (List.get(vec, char - 0x61) ?? 0) + 1).list
_ -> vec
)
|> List.any(|count| count > 1)
The compilation error is:
I am partway through parsing a record pattern, but I got stuck here:
6│ |> Str.walk_utf8(
7│ List.repeat(0, 26),
8│ |vec, char|
^I was expecting to see a closing parenthesis next, so try adding a )
and see if that helps?
List.range(0x41, 0x5A) ->
does not work in roc
You have to do something like 'a' | 'b' | 0x27 | ... ->
that or use an if.
Thank you
Last updated: Jul 06 2025 at 12:14 UTC