Scope
Where a variable can be seen: everywhere, inside one function, or inside one block.
Variable Scope
Otter must define where variables can be accessed.
Example:
Otter
name is "Jeff"
to greet
message is "Hello"
say name
.
The language must specify:
- whether functions can read variables outside themselves
- whether local variables disappear when the function ends
- whether nested blocks create new scopes
- how outer variables are changed deliberately
The preferred rule is:
Variables created inside a function belong to that function unless explicitly exposed.
Function Local Variables
Example:
Otter
to greet name
message is "Hello"
say message name
.
message exists only while greet is running.
After the function finishes, message should no longer be available outside that function.
Block Scope
Simple control-flow blocks should not automatically hide ordinary variables unless Otter later chooses strict lexical block scope.
Example:
Otter
ready is true
if ready
message is "Starting"
.
say message
This behavior needs one consistent rule across:
Output
if
while
for each
count
try
The exact rule should be frozen before more advanced closures or concurrency are added.