Stream: beginners

Topic: declarations that reference mutable variables


view this post on Zulip MorganEarlJones (Nov 13 2026 at 16:15):

Should non-effectful declarations be allowed to reference mutable variables? In the following code, the non-effectful value 'x' is defined as the most recent value of the mutable variable $y:

main! = |_args| {
var $x = "boop"
$x = "beep"
y = $x
$x = "boop"
echo!(y)
Ok({})
}

Wouldn't it be preferable to force some notation on y as with effectful functions?
i.e., y! = $x, or perhaps y$ = $x, to make explicit that the value assigned is dependent on the immediate value of a mutable variable.

view this post on Zulip Steve Howell (Nov 13 2026 at 16:32):

That sounds like a Rust feature. :smile:

I'm curious what the actual symptom is here. What pitfall are you trying to have Roc help you avoid?

view this post on Zulip Anton (Nov 13 2026 at 16:35):

The output is "beep" so the value of $x at the moment of assignment to y, so that all seems to make sense to me. At first I thought the value of y might change with the next assignment but this is not the case so that all seems fine as is.

view this post on Zulip Anton (Nov 13 2026 at 16:38):

In general, I would like to avoid special notation for things that only come up very rarely.

view this post on Zulip MorganEarlJones (Nov 13 2026 at 16:43):

admittedly I'm having a hard time imagining a scenario where this matters outside of a junior dev onboarding to a mature-but-poorly-written codebase where a relationship like this is buried a few declarations deep and an erroneous assumption is made about the declared value based on whichever occurrence of the mutable dependency the dev sees first

I suppose the easiest answer to this imagined problem would of course be "don't do it like that"

view this post on Zulip Steve Howell (Nov 13 2026 at 16:47):

When I see antipatterns like this, I have agents write automated gates to detect the pattern. See #off topic > shale programming language for my specific approach, but you just need to get agents to use the Roc AST and walk it.


Last updated: Nov 26 2026 at 20:35 UTC