Here is the rule, and it is stricter than Python's:
Module variables are invisible inside functions. A function sees its parameters, its own locals, other functions, structs, and imported vocabulary — nothing else. Data enters through parameters and leaves through the return value.
count = 5
fn bad[]
--- error: 'count' is a module variable, which a function does not
--- see — pass it as a parameter
return count + 1
The fix is always the same shape:
1 2 3 4 5 6
count = 5
fn bump[n]
return n + 1
log[bump[count]]expected output — from the book, verified by crow test --book
6A local that happens to reuse a module name shadows nothing — module
variables were never visible, so it's simply a fresh binding. No global
keyword, no nonlocal, no scope-resolution table to memorize.
Two reasons, and they're both load-bearing:
crow check all get harder.
Parameters-in, return-out means every dependency is visible at the
call site.The one sanctioned exception is the state of a program that serves
(chapter 12): view blocks, event handlers and derivations read a page's
reactive state, and a route's handler reads the derivations its app
holds — a managed channel, synchronized by the runtime, not ambient
mutation.