fibonacci.alia
~ 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 10

Alia

The “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→

The Core Extension Mechanism of the Language

What fundamentally sets Alia apart from traditional programming languages — together, these systems form a language kernel where syntax is definable, composable, and translatable.

·
Syntax Keyword System

Define any syntax structure with alias, from simple printing to complete control flow — the boundaries of syntax are yours to decide.

Alia
~ 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!'
}
·
Stack System

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.

Alia
~ *{} 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 accessible
·
Translation System

Translate language keywords into any natural language or symbolic system, so code can be written in your native tongue.

Alia
~ 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 '中文(简体)'
设 问候 为 '你好,世界!'
打印 问候
·
Testing System

Built-in test, assert, inspect, and breakpoint keywords let you write and debug tests without any external framework.

Alia
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ẞhell
·
Reference System

ref, load, and store provide indirect references to variables, enabling flexible state exchange and mutation within closed contexts.

Alia
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'
·
Compilation System

Override AST nodes and keywords with @compileEntry, @compileNode, and @compileAlias to define compilation for any target.

Alia
~ 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 .. ')'
}

Compilation Targets Already Supported

Rust
JavaScript