Stream: beginners

Topic: Why won't this compile?


view this post on Zulip Tom Hill (Apr 20 2025 at 21:52):

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?

view this post on Zulip Brendan Hansknecht (Apr 21 2025 at 02:18):

List.range(0x41, 0x5A) -> does not work in roc

view this post on Zulip Brendan Hansknecht (Apr 21 2025 at 02:19):

You have to do something like 'a' | 'b' | 0x27 | ... ->

view this post on Zulip Brendan Hansknecht (Apr 21 2025 at 02:19):

that or use an if.

view this post on Zulip Tom Hill (Apr 21 2025 at 10:53):

Thank you


Last updated: Jul 06 2025 at 12:14 UTC