Language Reference Manual

Language Reference Manual — Thorn 0.3

This is the full language reference for Thorn 0.3. It covers all syntax, built-in types, control flow, and the standard library. This is a draft document accompanying the 0.3 specification.


Variables & Types

No declaration keyword. Assign a value and Thorn infers the type.

x = 5
name = "Thorn"
active = on
nothing = void

Built-in types: number, text, on/off, void, list, map.

Tasks

task add(x, y) {
    send x + y
}
result = add(3, 4)

Conditionals

if (x > 5) {
    write("big")
} elif (x == 3) {
    write("three")
} else {
    write("small")
}

Loops

loop(on) { }           # forever
loop(15) { }           # 15 times
loop(i = 15) { }       # with counter
loop(x < 100) { }      # condition
loop(item = myList) { } # over list

Error Handling

err = risk {
    res = reach(url)
    send res.json
}
if (err != void) {
    write(v"failed: {err}")
}
try {
    # risky code
} catch(e) {
    write(e)
}

Concurrency

spawn(fetchData(url))
out = spawn(fetchData(url))
write(v"got: {out}") # waits here

Sections

section.global networking {
    task connect(url) { }
}
networking.connect("pawnet://ABC12")

Imports

need "myfile"
need "myfile" as m
need myTask from "myfile"
need time
need math
need random

Files & Folders

dcmnt = read("path/to/file")
dcmnt = file("path/to/file")
dcmnt.line(14)
dcmnt.write("content")
dcmnt.append("new line")
dcmnt.delete
f = folder("path/to/dir")
f = folder.create("path/to/dir")
f.files / f.folders

HTTP — reach

res = reach("https://example.com")
res = reach.post(url, data)
res.body / res.status / res.json

Keyword Reference

  • task — define a function
  • send — return a value
  • loop() — all looping patterns
  • risk — error handling
  • spawn() — concurrency
  • need — imports
  • section — code organisation
  • on / off — booleans
  • void — null / nothing
  • start — on when run directly
  • .force — push through obstacles
  • reach() — HTTP client
  • write() — print to stdout