Korr

Getting started

Docs index

1. Install

# Linux / macOS
curl -fsSL https://raw.githubusercontent.com/refkinscallv/korr/main/install.sh | bash
# Windows (PowerShell)
irm https://raw.githubusercontent.com/refkinscallv/korr/main/install.ps1 | iex

Open a new terminal and check that it works with korr version. Other options (installer files, archives, building from source), requirements and troubleshooting are in Installation.

2. Your first program

Create hello.krr:

let name = "world"
print("Hello, {name}!")

Run it:

korr hello.krr

Every Korr file ends in .krr. Code runs from top to bottom; there is no main function to write.

3. The five rules you need first

  1. Blocks are indented. A line that starts a block (if, for, fn, …) is followed by lines indented by 4 spaces. No braces, no colons, no end.
  2. One statement per line. No semicolons.
  3. Declare before use. let x = 1 creates a variable, x = 2 changes it. const values can never change. Using a name that does not exist is an error before the program starts.
  4. No silent conversions. "age: " + 5 is an error. Write "age: {5}".
  5. Errors tell you what to do. Read the tip: line.
let items = ["apple", "banana"]
for item in items
    if item.starts_with("a")
        print("{item} starts with a")
    else
        print(item)

4. The REPL

$ korr repl
>>> let xs = [1, 2, 3]
>>> xs.map(fn(x) => x * 10)
[10, 20, 30]
>>> fn square(n)
...     return n * n
...
>>> square(12)
144

End a multi-line block with an empty line. Type exit to quit.

5. Inline code and checks

korr -e 'print(2 ** 10)'           # run a one-liner
korr check app.krr                 # syntax + name check without running

6. A full-stack project in 30 seconds

korr new myapp
cd myapp
korr main.krr        # open http://localhost:8080
korr test            # 5 passing tests
korr build main.krr  # ./main: one file, no Korr install needed to run it

The project contains:

File Purpose
main.krr Routes, data model (struct Todo) and the server start
views.krr HTML templates with automatic escaping
app_test.krr Tests using app.request(): no network needed
public/style.css Static files served at /public/...

7. Reading an error

error[NameError]: Undefined variable 'totl'
  --> shop.krr:12
   |
12 |     print(totl)
   |
   = in checkout() called from line 30
   = tip: did you mean 'total'?

Next steps


Previous: Installation Docs index Next: Language guide