Documentation Hub
Language
Language Specification & Syntax
Detailed language reference covering types, explicit mutability, functions, pipeline operator, and structs.
NextViper Language Specification
Comprehensive reference for the NextViper syntax, lexical structure, type system, and control flow.
1. Variables & Mutability
NextViper enforces explicit mutability to eliminate state-related concurrency bugs.
Immutable Variables (`let`)
Variables declared with let cannot be mutated or rebound:
nextviper
let pi = 3.14159
let name = "NextViper"
// pi = 3.14 <-- Error: cannot reassign to immutable variableMutable Variables (`let mut`)
Variables intended to change must explicitly declare mut:
nextviper
let mut counter = 0
counter += 1
counter = counter * 2
print("Counter:", counter) // 22. Data Types
NextViper provides rich primitive and compound types:
Int (42, 1_000_000, 0xFF, 0b1010)Float (3.14, 1e-4)Bool (true, false)String (`"UTF-8 string withescapes"`)
[1, 2, 3, 4]{"key": "value", "status": 200}nil (represents absence of value)3. Functions & Closures
Standard Function
nextviper
fn calculate_loss(pred: Float, target: Float) -> Float {
let diff = pred - target
return diff * diff
}Arrow Expression Function
For single-expression functions:
nextviper
fn square(x) => x * x
fn is_even(n) => n % 2 == 0First-Class Functions & Lambdas
nextviper
let multiply = fn(a, b) => a * b
print(multiply(4, 5)) // 204. Pipeline Operator (`|>`)
NextViper includes a native pipeline operator to transform data fluently without nested parenthesis:
nextviper
let raw_data = " 12, 45, 78, 90 "
let clean_total = raw_data
|> trim()
|> split(",")
|> map(fn(s) => to_int(trim(s)))
|> filter(fn(n) => n > 20)
|> sum()
print("Total:", clean_total)5. Control Flow
If / Else
nextviper
if score >= 90 {
print("Grade: A")
} else if score >= 80 {
print("Grade: B")
} else {
print("Grade: C")
}Loops
nextviper
// For in range
for i in 0..5 {
print("Index:", i)
}
// For in collection
let items = ["data", "tensor", "ai"]
for item in items {
print("Module:", item)
}
// While loop
let mut n = 10
while n > 0 {
n -= 1
}
