Scope & mutation
Where names live, what functions can see, and which values are shared. Run a cell to see its output beside the expected one.
Functions read globals
A top-level scalar is visible inside every def.
Viv [1]
Assigning inside a def never touches a global scalar
Assignment in a function body creates a local variable; the global g keeps its value, 5.
Viv [2]
A def can change a global array
A def that stores into an element of a global array changes the global array; no return is needed.
Viv [3]
Assignment aliases arrays
b = a makes b refer to the same array; it does not copy the data. Changing b changes a.
Viv [4]
Array parameters alias too
A function mutating its array parameter mutates the caller's array.
Viv [5]
Closures see the current global
Capture is by reference for globals: rebinding y changes what f computes.
Viv [6]