~ Fibonacci sequence
alias fibonacci <Number n> -> {
if n <= 1 { return n }
let prev = 0
let curr = 1
let index = 2
while index <= n {
let next = prev + curr
prev = curr
curr = next
index ++
}
return curr
}
print fibonacci 10The “primordial” programming language
Syntax is the core of Alia. Through the keyword extension system, you can define, compose, and translate any syntax structure. From built-in testing to interactive debugging — the language itself is the tool.
Explore Alia→What fundamentally sets Alia apart from traditional programming languages — together, these systems form a language kernel where syntax is definable, composable, and translatable.
Define any syntax structure with alias, from simple printing to complete control flow — the boundaries of syntax are yours to decide.
~ Define custom control structures
alias repeat <Number times> times <Stack stack> -> {
for { let i = 0 } i < times { i ++ } {
stack.run()
}
}
~ Use the custom keyword
repeat 3 times {
print 'Hello Alia!'
}The stack is the execution core of Alia. Create a new context or reuse the original one — precisely control the scope and lifetime of your code.
~ *{} creates an independent context
let x = 0
const stack = *{
let x = 10
x + 5
}
const result = stack.run() ~ 15
print x ~ 0
~ {} reuses the original context
{
let y = 20
}.run()
print x + y ~ y is accessibleTranslate language keywords into any natural language or symbolic system, so code can be written in your native tongue.
~ Define a Chinese translation
@translate '中文(简体)'
print <Value val> -> 打印 <Value val>
@translate '中文(简体)'
let <Key n> = <Value v> -> 设 <Key n> 为 <Value v>
export this
~ Program in Chinese
@language '中文(简体)'
设 问候 为 '你好,世界!'
打印 问候Built-in test, assert, inspect, and breakpoint keywords let you write and debug tests without any external framework.
test 'math-operations' {
assert 1 + 1 == 2 'addition failed'
assert 10 > 5 'comparison failed'
assert 3 * 4 == 12 'multiplication failed'
}
test 'inspect-demo' {
const a = 42
inspect a 'value check failed'
const arr = [1, 2, 3]
inspect arr 'array inspection'
}
breakpoint ~ Enter the interactive Aliaẞhellref, load, and store provide indirect references to variables, enabling flexible state exchange and mutation within closed contexts.
let x = 42
let r = ref x
print load r ~ 42
store r 99
print x ~ 99
~ Swap variable values
let a = 'hello'
let b = 'world'
let ra = ref a
let rb = ref b
let tmp = load ra
store ra load rb
store rb tmp
print a ~ 'world'
print b ~ 'hello'Override AST nodes and keywords with @compileEntry, @compileNode, and @compileAlias to define compilation for any target.
~ Declare a compilation entry
@compileEntry js {
'use strict;\ncall @compileStart'
}
~ Override AST nodes
@compileNode "BinaryOp" -> js {
'(' .. _bound.left .. ' ' .. _bound.op .. ' ' .. _bound.right .. ')'
}
~ Override keywords
@compileAlias print <Value val> -> js {
'console.log(' .. val .. ')'
}On top of the extensible syntax kernel, Alia provides everything modern programming paradigms require — object orientation, error handling, type systems, and more.
class defines implementations, extends enables inheritance, and new instantiates objects.
class Person *[
name: '',
age: 0,
greet: alias -> {
'Hi, I am ' .. self.name
},
new: alias <String n> <Number a> -> {
self.name = n
self.age = a
}
]
const p = new Person('Alice', 30)
print p.greet()The try-catch-throw trio constructs a complete exception handling and recovery mechanism.
const divide = alias
<Number a> <Number b> -> {
if b == 0 {
throw 'Divisor cannot be zero'
}
a / b
}
try {
print divide(10, 0)
} catch (e) {
print 'Caught error: ' .. e
}
~ Custom error class
class MyError *
[msg: '', code: 0]
throw new MyError('Timeout', 500)Compile-time type annotations and typeOf runtime type checks deliver both safety and performance.
~ Type annotations (compile time)
const name: String = 'Alia'
const count: Number = 42
const items: Array = [1, 2, 3]
const flag: Boolean = true
~ Runtime type checks
if typeOf name == 'String' {
print 'name is a string'
}
~ Generic usage
const list: Array[Number] = [0]
list.push(count)*[] defines objects and [] defines arrays, with flexible property access.
~ Object definition
const car = *[
brand: 'Tesla',
model: 'Model 3',
features: ['autopilot', 'electric']
]
~ Nested objects
const company = *[
name: 'Alia Corp',
depts: *[ eng: 50, sales: 30 ]
]
print company.depts.englet declares variables and const declares constants. Stacks create local scopes, and *{} isolates a new context.
let x = 10
const PI = 3.14159
x = 20 ~ reassignment
x += 5 ~ increment assignment
x ++ ~ increment
~ Local scope
{
let inner = 'local variable'
print x ~ outer scope accessible
}.run()
print inner ~ errorrun/await manage independent threads, Channel enables inter-thread communication, and select provides multiplexed channel selection.
~ Launch an independent thread
const task = run Number {
print 'Hello from thread!'
42
}
print await task ~ 42
~ Inter-thread communication
const ch = new Channel[3]
ch.send 'hello'
ch.send 42
print ch.receive ~ 'hello'
print ch.receive ~ 42Compilation Targets Already Supported