Types and Values
XE is dynamically typed. Values carry their type at runtime, and operations either succeed according to XE's rules or fail with a runtime error.
The four runtime types
XE currently has four value kinds:
| Type | Example | Notes |
|---|---|---|
number | 42, 3.14 | Stored as numeric runtime values |
text | "hello" | Double-quoted strings |
boolean | true, false | Used directly in conditions |
list | [1, 2, 3] | Ordered collections with zero-based indexing |
Check a value's runtime type with type(...):
print(type(42))
print(type("XE"))
print(type([1, 2, 3]))Variables are mutable
XE currently has variables, not constants.
score = 10
score = score + 5
print(score)There is no separate const keyword right now. Reassignment is allowed unless the name is out of scope.
Numbers
Numbers support:
+-*/%
price = 99.5
tax = 0.5
print(price + tax)Division and modulo by zero raise runtime errors instead of silently returning fallback values.
Text
Text values use double quotes.
name = "XE"
print("Hello " + name)+ also performs concatenation if either operand is text.
print("Count: " + 3)That produces text output.
Booleans and truthiness
Boolean literals are:
truefalse
Conditions also use truthiness rules:
0is falsey- non-zero numbers are truthy
""is falsey- non-empty text is truthy
[]is falsey- non-empty lists are truthy
Example:
if [1, 2]:
print("non-empty lists are truthy")Lists
Lists are array-like collections backed by Rust Vec, so indexing is natural and efficient.
items = [10, 20, 30]
print(items[0])
print(length(items))Important current rules:
- indexing is zero-based
- negative indexing is not supported
- out-of-bounds access is a runtime error
- list mutation is not implemented yet
Conversion rules
convert(value, target) supports three targets:
"number""text""boolean"
Examples:
print(convert("42", "number"))
print(convert(123, "text"))
print(convert("", "boolean"))Current behavior:
- text to number must parse successfully
- invalid text-to-number conversion fails at runtime
- booleans convert to
1or0when targeting"number" - lists cannot be converted to numbers
Equality and comparison
Comparison operators:
==!=<><=>=
Ordering comparisons (<, >, <=, >=) are numeric comparisons. If you use them on non-number values, XE raises a runtime error.
Equality compares values of the same runtime kind naturally. Different runtime kinds are not treated as equal.
print(5 == 5)
print("xe" == "xe")
print(true == 1)The last line evaluates to false, not to an implicit coercion.
Next steps
- Continue with Control Flow
- Or jump to Functions and Scope
