Language Basics
Variables, types, operators, and fundamental language concepts.
Variables
Kria uses the set keyword to declare and assign variables.
Variables are dynamically typed and can hold any value.
Example
set x = 10
set y = 20
set sum = x + y
print(sum)
Variables persist during a session (in the REPL) or throughout a program. Kria is dynamically typed: values have runtime types, and bindings do not declare a fixed type.
Data Types
type(value) reports one of these runtime categories:
- Number — Signed 64-bit integers and double-precision floats; both report as
"number" - String — Text values with double quotes
- Boolean —
trueorfalse - Null — The explicit
nullvalue - Array — Ordered, mutable or immutable collections
- Object — Key-value pairs
- Function — First-class functions and closures
Example
set name = "Kria"
set isActive = true
set value = null
print(name)
Integers and floats
Integer and decimal/scientific-notation literals are supported. Integer-only division remains integer division; arithmetic mixing an integer and a float produces a float.
set whole = 7
set decimal = 2.5
set scientific = 1.2e3
print(whole / 2)
print(whole + decimal)
Arithmetic Operators
Kria supports standard arithmetic operations on numbers:
| Operator | Operation | Example |
|---|---|---|
+ |
Addition | 10 + 5 = 15 |
- |
Subtraction | 10 - 5 = 5 |
* |
Multiplication | 10 * 5 = 50 |
/ |
Division | 7 / 2 = 3 (integer division) |
A calculation involving a float produces a floating-point result; for example,
7 / 2.0 evaluates to 3.5. The + operator
also concatenates two strings. Dividing by zero is an error.
Example
set x = 10
set product = x * 20
print(product)
set quotient = 20 / x
print(quotient)
Comparison & Logical Operators
Compare values with relational operators. Combine conditions with logical operators:
| Operator | Meaning | Example |
|---|---|---|
== |
Equal to | 5 == 5 is true |
!= |
Not equal | 5 != 3 is true |
> |
Greater than | 10 > 5 is true |
< |
Less than | 5 < 10 is true |
>= |
Greater or equal | 10 >= 10 is true |
<= |
Less or equal | 5 <= 10 is true |
and |
Logical AND | true and false is false |
or |
Logical OR | true or false is true |
not |
Logical NOT | not false is true |
Example
set x = 10
set y = 20
if (x < y) {
print("x is less than y")
}
Conditions must evaluate to booleans. Kria does not convert other values
implicitly to true or false. The and and or
operators accept boolean operands. A current file-compilation limitation
can cause non-constant and/or expressions to fail
during compilation; avoid variable-based logical expressions in
.krx files until this is fixed.
Type Checking
Use the type() built-in function to check a value's type at runtime:
print(type(42))
print(type("hello"))
print(type(true))
print(type(null))
Returns one of: "number", "string", "boolean",
"null", "array", "object", or "function".