Playground
A tour of iyi, in 33 short programs.
Start at the top and work down. Read the program, press Run, see what it prints, then move to the next. Each one is a page you can come back to.
- 01
Welcome
One program, to see the shape of the thing. - 02
Basics
Modules, variables, types and functions: what every program is made of.- 2modulesModules: every file is one, and
importbrings another in. - 3exports
import x::{...}: bring a module's exported names in, unqualified. - 4variablesVariables: assign a value and the type follows.
- 5typesThe basic types, and what each literal is.
- 6conversionsConversions are explicit: nothing changes type on its own.
- 7constantsConstants: a capitalised name, assigned once.
- 8functionsFunctions:
def, typed parameters, a typed result. - 9returnsMore than one result: a tuple, unpacked at the call.
- 10nilnil is a value, and the type says whether it can appear.
- 2modulesModules: every file is one, and
- 03
Flow control
Loops, ranges, conditions, case, and cleanup with defer. - 04
Data
Structs, classes, arrays, hashes, tuples and blocks.- 16structsA struct: named fields, a constructor, methods.
- 17classesA class is a reference: two names can point at one object.
- 18arraysArrays: ordered, growable, one element type.
- 19hashesHashes: keys to values, in insertion order.
- 20tuplesTuples: a fixed group of values, each with its own type.
- 21blocksBlocks and closures: code you hand to a function.
- 05
Methods and traits
Behaviour on types, traits that name it, unions and errors as values.- 22methodsMethods: functions that belong to a type.
- 23traitsA trait: a set of methods a type promises to have.
- 24dispatchA trait is a type: one list, many kinds, one question.
- 25defaultsDefault methods: a trait can carry bodies of its own.
- 26unionsUnion types: a value that is one of several types.
- 27errorsErrors are values. A function that can fail says so in its type.
- 28stringsStrings, and
to_s: how a type says what it looks like.
- 06
Generics
Functions and types that work for any type, and bounds that say which. - 07
Concurrency
Tasks in a group, and channels between them.
Done with the tour? Learn the one rule that makes iyi its own language, in eight lessons that each run a real program from the repository.
native Each program runs from the module the iyi compiler built for it, checked against its recording before it starts. A step marked native uses tasks, which the browser's target cannot run yet, so it shows what the program printed natively instead. You can type in any of the panes, and the page says which bytes a run will use the moment what is in one stops being the recorded file, because nothing on these pages compiles what you type. How this works