A tiny, expression-oriented programming language written in Rust
chen_lang is a dynamic, interpreted programming language designed for learning and experimentation. It features a clean syntax, expression-based control flow, and first-class functions.
- Expression-Oriented:
if/elseblocks and code blocks are expressions that return values. - Dynamic Typing: Supports Integers, Floats, Strings, Booleans, and Null.
- Functions: First-class functions with implicit returns.
- Control Flow:
if/elseexpressions,forloops,break, andcontinue. - Object System: Supports object literals, property access, indexing, and metatables.
- Scope Isolation: Block-scoped variables.
let name = "Chen Lang"
println("Hello, " + name + "!")
# Output: Hello, Chen Lang!In chen_lang, if/else is an expression, meaning it returns a value.
let a = 10
let result = if a > 5 {
"Greater"
} else {
"Smaller"
}
println(result)
# Output: GreaterFunctions implicitly return the value of the last expression.
def add(a, b) {
a + b # Implicit return
}
let sum = add(3, 5)
println(sum)
# Output: 8def fib(n) {
if n <= 1 {
n
} else {
fib(n - 1) + fib(n - 2)
}
}
println(fib(10))
# Output: 55# Print multiplication table
let i = 1
for i <= 9 {
let j = 1
for j <= i {
let prod = i * j
print(j + "x" + i + "=" + prod + " ")
j = j + 1
}
println("")
i = i + 1
}# Object literal
let person = #{
name: "Alice",
age: 25
}
# Property access
println(person.name) # Output: Alice
# Property assignment
person.age = 26
# Index access
let key = "name"
println(person[key]) # Output: Alice- Integer:
1,42,-10 - Float:
3.14,-0.01 - String:
"Hello World" - Boolean:
true,false - Null:
null(implicit return for empty blocks or if without else)
- Arithmetic:
+,-,*,/,% - Comparison:
>,>=,<,<=,==,!= - Logical:
&&,||,!
# This is a single-line comment- Core: Integers, Booleans, Arithmetic, Logic
- Control Flow:
if/else(expression),forloops,break,continue - Functions: Definition, Call, Recursion, Implicit Return
- Types: Floats, Strings
- Object System: Object literals, property access, indexing, metatables (can be used as arrays)
- Standard Library: File I/O, Math functions
- Error Handling: Try/Catch or Result type
MIT License