Stream: beginners

Topic: circular variable definition / indentation


view this post on Zulip Ghislain (Sep 25 2022 at 19:32):

Hi,
Is this an expected behaviors?

  1. With this total variable, I get the error of "CIRCULAR DEFINITION", the variables cannot conflict though.
    total =
        []
        |> List.walk { total: "" } \{ total }, _ ->
            { total }
  1. With the naming change, if after the List.walk I want to |> .total, I can't find how the indent it. The compiler always think I'm still in the List.walk callback.
    res =
        []
        |> List.walk { total: "" } \{ total }, _ ->
            { total }
        |> .total

view this post on Zulip jan kili (Sep 25 2022 at 19:38):

Regarding #2, what happens if you put parentheses around your function?

view this post on Zulip jan kili (Sep 25 2022 at 19:39):

Parentheses often fix scope/indentation issues for me

view this post on Zulip Ayaz Hafiz (Sep 25 2022 at 19:42):

For the first, that error happens because Roc does not allow variable shadowing, and total is shadowed in the inner lambda. That error message should be made better though.

view this post on Zulip Ghislain (Sep 25 2022 at 19:44):

In my mind, the variable did not exist before the assignement (total =)

view this post on Zulip Ghislain (Sep 25 2022 at 19:45):

I didn't see it as shadowing

view this post on Zulip Ayaz Hafiz (Sep 25 2022 at 19:53):

it is this way because “total” could be defined as recursive, that is, you could do something like “total = \_ -> total {}”


Last updated: Jul 06 2025 at 12:14 UTC