Skip to content

Variables

Variables allow NXL programs to store values.

A declaration looks like:

let age = 23
let name = "Tanmoy"

The interpreter evaluates the initializer, creates a runtime value, and stores it in the environment.

Conceptually:

"Tanmoy"
Value::String
Environment
name → "Tanmoy"

When NXL evaluates:

print(name)

the interpreter performs the equivalent of:

Identifier("name")
Environment.get("name")
Value::String("Tanmoy")

The environment also has an assign() operation.

The intended behavior is:

let age = 23
age = 24

This updates the existing variable.

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 = 20

Inside the block, x refers to 20; outside, it refers to 10.

Parent environments allow nested scopes to find values from outer scopes.