Kronos

Quick Reference

Fast reference guide for Kronos syntax

Quick Reference

Syntax cheat sheet for Kronos. For detailed explanations, see the Language Reference.

Variables

set name to "Alice"      # Immutable
let counter to 0         # Mutable
let age to 25 as number  # With type annotation

Data Types

TypeExample
Number42, 3.14, -10
String"Hello", f"Hi {name}"
Booleantrue, false
Nullnull
Listlist 1, 2, 3
Mapmap key: "value"

Operators

OperationSyntax
Additiona plus b
Subtractiona minus b
Multiplicationa times b
Divisiona divided by b
Moduloa mod b
Equala is equal b
Not equala is not equal b
Greatera is greater than b
Lessa is less than b
And/Or/Nota and b, a or b, not a

Control Flow

# Conditional
if condition:
    statement

# For loop
for i in range 1 to 10:
    print i

# For-each loop
for item in items:
    print item

# While loop
while condition:
    statement

Functions

function greet with name:
    print f"Hello, {name}!"

call greet with "Alice"

Strings

set char to text at 0           # Indexing
set slice to text from 0 to 5   # Slicing
set msg to f"Hello, {name}!"    # F-strings

Lists

set nums to list 1, 2, 3
print nums at 0                 # Access: 1
let nums at 0 to 10             # Modify

Maps

set user to map name: "Alice", age: 30
print user at "name"            # Access
delete user at "age"            # Delete key

Imports

import math
import utils from "utils.kr"

Exception Handling

try:
    raise "Error"
catch error:
    print error
finally:
    print "Done"

File I/O

set content to call read_file with "file.txt"
call write_file with "out.txt", "Hello"

Common Functions

call len with items             # Length
call uppercase with text        # "HELLO"
call split with text, ","       # Split string
call sort with numbers          # Sort list
call to_number with "42"        # Parse number

Running Programs

./kronos script.kr    # Run file
./kronos              # Start REPL
./kronos -e "code"    # Execute inline

On this page