It is based on Toki Pona, a constructed human language by Sonja Lang. It takes inspiration from prior art on the wiki Esolang, mainly toki pi ilo nanpa, while trying to be closer to the spirit of Toki Pona.
toki ilo pona can be written in Latin text, separating words with spaces. Or, it can be written with Sitelen Pona glyphs. As of writing, these are encoded in the UCSUR. (If they are ever added to Unicode, those codepoints should also be supported.)
37 keywords and one alias are used:
A command ends at the end of a line, or at a period, interpunct, colon, exclamation point, or question mark. Other punctuation and glyph combiners are ignored outside of a string.
o toki e [value]
Many commands allow repeating the argument marker. (In Latin text, it is conventional to separate arguments with a comma.) Print two things in one command:
o toki e [value], e [value]
Commands are heavily limited in their syntax, but most can be joined.
ni references the subject of the following command, which is run first. (In Latin text, it is conventional to end
ni commands with a colon.)
Initialize or set a variable:
[type] [Name] o [value]
The variable name can be multiple words. (It should also follow Toki Pona phonotactics.) In Latin text, each word must start with an uppercase letter. In Sitelen Pona, the whole name must be written in a cartouche.
The type is treated as a part of the variable name, and always goes before it. This means that variables of different types can share a name, if absolutely necessary.
A value can be preceded by its type with no change in meaning. For a numeric example,
ala is equivalent to
If the name is excluded from a variable declaration, the command will serve as a temporary value that can be substituted back into
lon type stores a boolean. The boolean true is
The boolean false is
ala. Because a value can be preceded by its type,
lon ala also works.
The not operator is
The or operator is
[boolean] anu [boolean].
nanpa type stores an integer.
ala is 0.
Other integers are formed with Toki Pona numerals, additive from highest to lowest value.
A negative number is formed with
jasima at the end.
An addend is formed with
kin after it. Increment a variable:
nanpa [Name] o wan kin
Print the sum of 1 + 2:
o toki e ni: nanpa o wan, o tu kin
A boolean is treated as a one-bit number. Cast a boolean to
nanpa [Name] o [boolean]
Casting a number to a boolean yields
ala if it is 0, and
nimi type stores a string. Strings are delimited with
te … to. Outer whitespace is trimmed. If the string continues to the end of the line, the
to can be dropped.
A string that concatenates onto a previous one is formed with
kin after it.
o toki e te toki, ma o!
toki, ma o!
Cast a boolean to its name:
nimi [Name] o [boolean]
Casting a string to a boolean yields
ala if it is empty, and
Cast a number to a string:
nimi [Name] o [number]
Following a string with a number returns the character at that index. Strings are one-indexed.
Character at position i:
nimi [Name] o [string] nanpa I
suli can be used here as a number corresponding to the string's length. This string–number trick can cast to a number representing the index:
nanpa [Name] o [string] nanpa suli
nimi [Name] o [string] ni: nanpa o suli, o wan jasima kin
pakala throws an error with a stack trace when used, unless a variable of its type is defined. Define a custom error message and throw it later:
pakala [Name] o [string]
o pakala [Name]
Built-in commands also use
pakala. For example, if a string that does not represent a number is cast to a number, it throws
Control flow uses
Tabs are used to indent code blocks.
ni cannot be used in the condition.
Values can only be compared in a condition.=
[value] li sama [value] la
[value] li sama ala [value] la
[value] li lili tawa [value] la
[value] li suli tawa [value] la
[value] li suli ala tawa [value] la
[value] li lili ala tawa [value] la
o awen· loops from the head of the latest block. It retries the condition, then continues down the corresponding branch.
The for loop can be implemented as a "while i meets a comparison" loop:
nanpa I o [min]
nanpa I li suli ala tawa [max] la
nanpa I o wan kin
o weka· breaks out of a block.
nasin [Name] kepeken [argument] la
A function can have multiple arguments.
Functions with different argument types can share a name.
Invoke a function:
o nasin [Name] e [argument]
A function must be defined before the place it is invoked. Otherwise, the computer will be confused because you haven't given it context for what the function is.
[value] o weka· returns a value.
Print the product of 12 × 10, then the factorial 5!:
nasin Leko kepeken nanpa Tenpo, kepeken nanpa Suli, la
lon Jasima o ala
nanpa Tenpo li lili tawa ala la
nanpa Tenpo o nanpa Tenpo jasima
lon Jasima o lon
nanpa Leko o ala
nanpa Tenpo li suli tawa ala la
nanpa Leko o nanpa Suli kin
nanpa Tenpo o wan jasima kin
lon Jasima la
nanpa Leko o nanpa Leko jasima
nanpa Leko o weka
o toki e ni: o nasin Leko e luka luka tu, e luka luka
nasin Patowijo kepeken nanpa Suli la
nanpa Suli li lili tawa ala la
o pakala te nanpa Suli li ken ala lili tawa ala
nanpa Suli li suli ala tawa wan la
wan o weka
nanpa Suli o wan jasima kin
nanpa o nasin Leko e nanpa Suli, e ni, o weka:
o nasin Patowijo e nanpa Suli
o toki e ni: o nasin Patowijo e luka