Tyr Language Tutorial

The third layer of the Tyre language ecosystem

Introduction

Tyr is a natural-language-inspired programming language. It has no parentheses, no braces, no indentation — the nesting of expressions is determined entirely by the word type of each word, which is recognizable from its consonant structure.

Tyr compiles to Ty, which compiles to T, which compiles to C. Each layer removes a level of explicit syntax:

TTyTyr
AbstractionC levelRust levelNatural language
SyntaxC-like / SLNC-like / SLNNo brackets
Functionsfntype + implRelations (words)
TypesNewtypesGeneric newtypesSpecifier words
ArgumentsPositionalType-basedWord-type-based
Definitionsfn, type, lettype, impl, letOnly binding

Word Types

Every word belongs to exactly one of four categories, determined by its consonant structure:

Word TypeStructureEffectExample
Object (O)Consonants before and after vowelCloses one levelvan, zan, nam
Specifier (S)Consonants only before vowelLevel stays (qualifies next Object)na, fa, vi
Relation (R)Consonants only after vowelOpens one levelan, un, is
Modifier (M)Starts with a stop (b, c, d)Level stays (modifies previous word)da, ba

The word type is always unambiguous. You can tell what any word does just by looking at its consonant pattern.

Phonotactics

Tyr uses a small, precise phoneme inventory:

CategorySounds
Vowelsi, a, u
Approximantsy, v
Liquidsl
Nasalsn, m
Fricativesf, s, z, h
Stopsb, c, d

Each word has one syllable: an optional onset (consonants before the vowel), a vowel, and an optional coda (consonants after the vowel). A word needs at least one consonant, so a bare vowel such as a or i is rejected. A leading stop is a Modifier marker; the rest of the word is checked like any other.

Onset order: fricative → liquid/nasal → approximant → vowel. Each slot holds at most one sound, and a slot may be skipped (svan, slva, nya).
Coda order: vowel → approximant/liquid → nasal/fricative. Each slot holds at most one sound (alf).

Valid words: an, van, sli, uvh, da, nam, alf.
Invalid: mn, vy, lna, nfa, alfn, a.

Phonotactics only decides a word's type; the word must also exist in the vocabulary (below) unless it is a number or a variable name. Words are separated by a space, a newline, - or ' (ul-zan-zan. works), and a sentence separator must be followed by one of these.

Auto-Bracketing

A level counter determines nesting. It starts at 0:

A sentence is complete when an Object arrives while the level is 0. A further word after that is an error (nan van.), and so is an end of sentence while a Relation is still waiting for its second argument (an nan.).

S O          → S(O)                Specifier applied to Object
R O O        → R(O, O)             Relation with two arguments
R S O O      → R(S(O), O)          First argument qualified
R O R O O    → R(O, R(O, O))       Nested relation
R M O O      → M(R)(O, O)          Modifier changes Relation

A Relation always takes exactly two arguments: the first from its subordinate clause (level + 1), the second as the main object (closing the Relation's own level).

Nested Relations

Multiple Relations chain naturally from right to left. Each one opens a level, each Object closes one:

R₁  R₂  R₃  O₁  O₂  O₃  O₄
0 → 1 → 2 → 3 → 2 → 1 → 0

Result: R₁(R₂(R₃(O₁, O₂), O₃), O₄)

This is right-to-left currying. Each Relation with only one argument is partial — it waits for the second. The rightmost Object completes all pending Relations.

Arithmetic

The four basic arithmetic operations are Relations:

WordMeaningResult
anaddan(a, b) = a + b
unsubtractun(a, b) = a − b
ulmultiplyul(a, b) = a × b
ildivideil(a, b) = a / b

Number words (nan = 0, van = 1, yan = 2, lan = 3, man = 4, san = 5, zan = 6):

an van van         → add(1, 1) = 2
un zan van         → sub(6, 1) = 5
ul yan lan         → mul(2, 3) = 6

Nested arithmetic:

ul an van van zan   → mul(add(1, 1), 6) = 12

Step by step:
  ul: Relation, level 0 → 1
  an: Relation, level 1 → 2
  van: Object, level 2 → 1 (first arg of an)
  van: Object, level 1 → 0 (second arg of an, first arg of ul)
  zan: Object, level 0 → sentence complete (second arg of ul)

Numeric Literals

In addition to named number words, Tyr supports decimal integer literals directly:

an 3 7             → add(3, 7) = 10
ul 6 7             → mul(6, 7) = 42

Numeric literals are always Objects. They can appear anywhere a named Object word would.

Print

The Specifier la prints a value:

la an van van.      → print(add(1, 1))    outputs: 2
la ul 6 7.          → print(mul(6, 7))    outputs: 42

la is a Specifier, so it qualifies the next Object expression and prints it. Every useful Tyr program will have la somewhere.

Specifiers

A Specifier qualifies an Object. It's like a type constructor or unary operation applied to a value:

na van              → i64(1) = integer 1
fa van              → f64(1) = float 1.0
la an van van       → print(add(1, 1)) = outputs 2

Specifiers chain right-to-left:

S₁ S₂ O             → S₁(S₂(O))
la na van            → print(i64(1))

Current Specifiers:

WordMeaning
nainteger type (i64)
fafloat type (f64)
laprint

na and fa convert their object to i64 / f64: la na il fa 7 fa yan. prints 3, la il fa 7 fa yan. prints 3.5.

Modifiers

Modifiers start with a stop consonant (b, c, d) and transform the word they follow. They don't change the bracket structure.

Opposite

da inverts a Relation's meaning. It is placed after the Relation it modifies:

an da van van        → sub(1, 1) = 0
ul da van zan        → div(1, 6)

da on an (add) gives subtraction. On ul (multiply) gives division. On us (less) gives greater, and on as (greater) gives less. On is (equal) it gives not-equal: la is da van zan. prints true. A da directly after la modifies the print Specifier instead and has no effect, so la da is van zan. prints false. On uvh (power) it gives root.

Passive

ba swaps the two arguments of a Relation. It takes effect after the Relation's first argument:

un van zan           → sub(1, 6) = −5
un van ba zan        → sub(6, 1) = 5

Normally, the first Object after a Relation is the first argument (subordinate clause), and the second Object is the main argument. ba reverses this. Placed directly after the Relation (un ba van zan), it has the same effect: the result is 5.

Binding

The Relation in binds a value to a name:

in na van val        → let val = na(1)

in: Relation (bind), level 0 → 1
na: Specifier, level stays 1
van: Object, level 1 → 0 (first arg: the value na(1))
val: Object, level 0 → sentence complete (second arg: the name)

This is Tyr's only definition mechanism. There's no type, no fn, no impl. You can only bind values to names for later reuse.

in an van van sum.   → let sum = add(1, 1)
la an sum sum.       → print(add(sum, sum)) = print(4)

Mutable State

By default, bindings are immutable. The Modifier bu on in creates a mutable binding (var instead of let):

in bu nan val.       → var val = 0

The Relation um assigns a new value to a mutable variable:

um val van.          → val := 1

um takes the variable name as first argument and the new value as second: um name value.

in bu nan val.               var val = 0
um val an val van.           val := val + 1
um val an val van.           val := val + 1
um val an val van.           val := val + 1
la val.                      print(val) → 3

Comparison

Comparisons are Relations that return boolean values:

WordMeaningOpposite (da)
isequalnot equal
usless thangreater than
asgreater thanless than
is van van           → equal(1, 1) = true
us van zan           → less(1, 6) = true
as zan van           → greater(6, 1) = true

Conditionals

The Relation if takes a condition (first argument) and a result (second argument):

if us van zan van    → if(less(1, 6), 1)

if: Relation, level 0 → 1
us: Relation, level 1 → 2
van: Object, level 2 → 1 (first arg of us)
zan: Object, level 1 → 0 (second arg of us, first arg of if)
van: Object, level 0 → sentence complete (second arg of if: result)

There is no else. If the condition is false, the expression produces no value. For an else branch, write a second sentence with the negated comparison:

if us van zan la van.        → if less(1, 6) then print(1)
if us da van zan la nan.     → if greater(1, 6) then print(0)

da on us (less) gives greater. Booleans sun (true) and nun (false) can also be used as conditions.

Loops

The Relation uf creates a while loop. Like if, it takes a condition and a body:

in bu nan val.
uf us val 10 um val an val van.
la val.                          → prints 10

uf condition body repeats body while condition is true.

Sequence

For loop bodies with multiple statements, the Relation am (sequence) combines two expressions into a block:

am stmt1 stmt2       → { stmt1; stmt2; }

am chains naturally: am stmt1 am stmt2 stmt3 flattens to { stmt1; stmt2; stmt3; }.

in bu nan sum.
in bu van val.
uf us val 11 am um sum an sum val um val an val van.
la sum.                          → prints 55 (sum of 1..10)

Sentences

A sentence is a complete expression — the level counter starts at 0 and the last Object closes it back down. Sentences are separated by punctuation marks: . , ; : ! ?

la an van van.       → sentence 1: print(add(1, 1))
la ul zan zan.       → sentence 2: print(mul(6, 6))

Each sentence becomes one statement in the compiled output. Multiple sentences in a program execute in order. A sentence whose value is never used, such as a bare an van van., is rejected by the C compiler (statement with no effect) in a file; only the REPL prints bare expressions for you.

No Definitions

Tyr removes one more definition layer compared to Ty:

TTyTyr
fn twice(n: i32) -> i32 { n * 2 }type n = i32;
type twice = n;
impl twice -> i32 { n * 2 }
Relations are words.
No definition in code.
type x = f32;type x = f32;Types are Specifier words.
No definition in code.
let sum = a + b;let sum = a + b;in an lum him sum

Types and operations exist because words exist. The vocabulary (dictionary) defines all types and their behavior. Tyr programs compose existing words; they never define new ones.

New concepts arise through:

Build & Run

cargo run -p tyre-tyr -- run examples/tyr/hello.tyr     # compile and run
cargo run -p tyre-tyr -- build examples/tyr/hello.tyr   # compile to binary
cargo run -p tyre-tyr -- c examples/tyr/hello.tyr       # output generated C
cargo run -p tyre-tyr -- ty examples/tyr/hello.tyr      # print the Ty AST (debug)
cargo run -p tyre-tyr -- repl                           # interactive mode

The package is tyre-tyr; the binary it builds is tyr. Tyr source files use the .tyr extension.

Interactive Mode

The REPL compiles and runs each line through the full pipeline. Expressions are auto-printed — no need to write la:

→ an van van.
2
→ :lines
  1  la an van van.
→ :c
#include <stdint.h>
...

Commands: :q (or :quit) quit, :c show C output, :lines show all entered lines, :reset clear state.

A binding typed into the REPL is kept: in ul 6 7 sum. prints nothing, and a later sum. prints 42. Variable names follow the same phonotactics as all words, so a name like answer is rejected (Character 'w' is not allowed).

Compilation

Tyr compiles through three stages:

  1. Tyr → Ty — word types become Ty AST nodes. Relations become binary operations or callable tuples. Specifiers become type constructions. in becomes let. if becomes if.
  2. Ty → T — generics are monomorphized, impl blocks become functions.
  3. T → C — the final output is standard C, compiled with cc.

Vocabulary Reference

Objects (O) — Values

WordValue
nan0
van1
yan2
lan3
man4
san5
zan6
suntrue
nunfalse
integers42, 100, etc.
unknown wordsvariable names (sum, val, etc.)

Relations (R) — Binary Operations

WordMeaningOpposite (da)
anaddsubtract
unsubtractadd
ulmultiplydivide
ildividemultiply
uvhpower (computed as a float)root
ivhroot (computed as a float)power
isequalnot equal
usless thangreater than
asgreater thanless than
inbind (let)—
umassign (:=)—
ifconditional— (unless is not implemented)
ufwhile loop—
amsequence (block)—

Specifiers (S) — Type Constructors

WordMeaning
nainteger type (i64)
fafloat type (f64)
laprint

Modifiers (M) — Word Transformers

WordEffect
daOpposite: inverts the meaning of a Relation
baPassive: swaps the two arguments of a Relation
buMutable: in bu = mutable binding (var)