Variables leaking

I’ve been thinking about the change made 2-3 years ago where it’s
no longer permitted to set variables inside a case statement (or similar).

Is it fair to summarize this by saying: Variable values can pass from an
outer context to a more inner one, but those variables cannot be bound
to new values (such that the outer context changes)?

This afaik applies to any “block” of code nested inside a larger context –
the “guts” of an if, case, cond, code passed to a macro…

Am I looking at this correctly or not?

Hal

In short ways, binding is valid only within it’s block.

x = 1

if true do
  # we start new block there
  x = 2
  # there `x` has new binding
end # block ended so all it's bindings as well

# there `x` has meaning of it's previous binding

And if you want to conditionally bind

x = if true do
    1
else
    2
end

Yes, thank you…

Of course, the value of x is still known inside the block until it is reassigned…

x = 1
IO.puts x

if true do 
  IO.puts x
  x = 2     
  IO.puts x
end 

IO.puts x

# Prints: 1, 1, 2, 1

Hal