Language Basics
XE is intentionally small. The syntax is indentation-based and close to Python in shape, but the compiler lowers everything into Rust.
If you want the book-like path through the docs, read the chapters in this order:
Hello World
Every language starts with printing a message.
print("Hello, World!")print is a built-in function. It writes values to the screen.
Numbers and variables
Variables are just names that hold values.
x = 10
y = 20
print(x + y)What happens:
xgets10ygets20x + yevaluates to30printshows the result
Arithmetic operators available now:
+-*/%
Text
Text values are written in double quotes.
name = "XE"
print("Hello " + name)The + operator can also join text values.
Booleans
Boolean values are true and false.
ready = true
print(type(ready))Input and conversion
input() always returns text, even when the user types digits. Convert it before using it as a number.
age_text = input("Enter your age: ")
age = convert(age_text, "number")
if age >= 18:
print("Adult")
else:
print("Minor")Valid conversion targets currently documented in XE:
"number""text""boolean"
Conditionals
XE uses indentation-based blocks for if, elif, and else.
score = 82
if score >= 90:
print("A")
elif score >= 80:
print("B")
else:
print("Keep going")Comparison operators:
==!=<><=>=
Logical operators:
andornot
Repeat loops
XE currently has fixed-count loops through repeat N times.
repeat 3 times:
print("XE")N can be a number or a variable that stores a number.
Assignments inside the loop update outer variables if they already exist:
count = 0
repeat 3 times:
count = count + 1
print(count)While loops
Use while when the loop should keep running until a condition becomes false.
count = 0
while count < 3:
print(count)
count = count + 1For loops
Use for name in iterable to walk through a list or text value.
total = 0
for item in [1, 2, 3]:
total = total + item
print(total)For text, XE iterates one character at a time:
for ch in "XE":
print(ch)Break and continue
Inside repeat, while, and for loops you can use:
breakto leave the loop immediatelycontinueto skip to the next iteration
count = 0
while true:
count = count + 1
if count == 2:
continue
if count == 4:
break
print(count)Functions
Functions let you name reusable logic.
function add(a, b):
return a + b
print(add(3, 5))You can also define functions that do an action and return 0:
function greet(name):
print("Hello " + name)
return 0
greet("World")Recursion
Recursion works and is useful for classic examples like Fibonacci.
function fib(n):
if n <= 1:
return n
return fib(n - 1) + fib(n - 2)
print(fib(10))Lists
Lists hold ordered values.
fruits = ["apple", "banana", "cherry"]
print(fruits[0])
print(length(fruits))Notes:
- list indexing starts at
0 fruits[0]is the first elementlength(fruits)returns the number of elements
Built-ins
Current built-ins:
print(...)input(prompt)length(value)type(value)convert(value, "target")
Quick summary
- Data types: number, text, boolean, list
- Typing: dynamic at runtime, with semantic checks for names and control flow
- Control flow:
if,elif,else,repeat N times,while,for ... in ... - Loop control:
break,continue - Functions:
function name(args):andreturn - Blocks: indentation with spaces, not braces
For the more detailed version of each topic, continue with:
