Variables
Variables
Section titled “Variables”Variables allow NXL programs to store values.
A declaration looks like:
let age = 23let name = "Tanmoy"The interpreter evaluates the initializer, creates a runtime value, and stores it in the environment.
Conceptually:
"Tanmoy" ↓Value::String ↓Environment ↓name → "Tanmoy"Variable lookup
Section titled “Variable lookup”When NXL evaluates:
print(name)the interpreter performs the equivalent of:
Identifier("name") ↓Environment.get("name") ↓Value::String("Tanmoy")Assignment
Section titled “Assignment”The environment also has an assign() operation.
The intended behavior is:
let age = 23age = 24This updates the existing variable.
Scopes
Section titled “Scopes”NXL uses environments to represent scopes.
let x = 10
if true { let x = 20 print(x)}
print(x)Conceptually:
Global│├── x = 10│└── If Block │ └── x = 20Inside the block, x refers to 20; outside, it refers to 10.
Parent environments allow nested scopes to find values from outer scopes.