NouvaLang v0.1.0
GitHub

Variables & Data Types

Learn how to declare mutable variables, immutable constants, and leverage static typing and type inference in NouvaLang.


1. Primitive Types

NouvaLang provides four core primitive types:

Type Description Example
int 64-bit signed integer 42, -15, 0
float 64-bit IEEE 754 floating-point 3.14159, -0.5
str UTF-8 encoded string literal "Hello, Nouva!"
bool Boolean truth value true, false

2. Mutable Variables (let)

Variables are declared using the let keyword with an explicit type annotation:

let count: int = 10;
let price: float = 99.95;
let message: str = "Order confirmed";
let is_active: bool = true;

// Reassignment
count = 20;

3. Type Inference (auto)

If you prefer automatic type inference while retaining static type safety, use auto:

let score: auto = 100;        // Inferred as int
let tax: auto = 0.15;         // Inferred as float
let title: auto = "Nouva";    // Inferred as str
let flag: auto = false;       // Inferred as bool

4. Constants (const)

Immutable constants are declared using the const keyword. Reassigning to a constant triggers a runtime error:

const MAX_USERS: int = 500;
const PI: float = 3.1415926535;

// The following will throw an error:
// MAX_USERS = 600; // Error: Cannot reassign to constant variable 'MAX_USERS'