Intro
What is toki pi ilo sona?
toki pi ilo sona is a programming language that is written with the sitelen pona hiroglyphic system for toki pona.
To write with this system on computers, this language uses "the currently-unused UCSUR range of 0xEE00 to 0xEE85". You can find more info on the sitelen pona pona website.
None of what is here is set in stone, its a crazy project and I’m sure that many people will have great suggestions to change and improve it!
Why?
This project is (obviously) not intended to be a practical programming language. This is more of an exercise for myself and also something that has brought very interesting points up.
Due to toki pona’s very minimal vocabulary and basic grammar rules, the programming language naturally is very similar to grammatically correct text. Something like this could never be achieved when using English (or any other language for that matter) as it is too complex and inconsistent.
Philosophy
When creating this standard, I did the best I could to stay as close to correct grammar. In most programming languages, the syntax doesn’t follow any logic. For the most part, people (programmers) have an intuition based on de facto practices. For this project, I wanted to do something a bit different, I would rather have longer syntax if it meant that it had a clear link to what it meant. A good example for this is comments, I could have easily used something such as //
, but I chose to use
:
How can you use it?
For now, you can’t run code in this programming language, it is just a standard/set of rules. I’m hoping that this will change soon, I’ve made some prototype compilers and as soon as one is ready to play around with I’ll update this file with details on how to use it.
Syntax
Comments
Comments in code are simply parts that you want the computer to ignore. Therefore, to create one, you simply need to tell the computer just that:
: COMMENT
These comments will continue until the end of the line. For multi line comments, you can use
: COMMENT \ COMMENT \ COMMENT \ COMMENT
Variables
Variables are things, they can be a value, or be an object. They act similarly to variables in python and can switch between data types. To create a variable, you must also set its value using
VARNAMEVALUE. VARNAMEOTHERVAR. VARNAME: ARITHMATIC. VARNAMEFUNCTION.
More information in Functions about getting a returned value. also note that
VARNAMEOTHERVAR.
can be used, but as you are saying that it is the other variable and not the same as, changing one will change the other.
Variable names need to adhere to these rules:
-
Due to the nature of Negation syntax, they cannot end with
Special temporary variable
As you cannot use the Alternate arithmatic in chains, there is a special variable that is simply defined as
VALUE.
And you refer to this value with
This is useful as it removes the need to have lots of redundant variables.
Data types
There are three data types in toki pi ilo sina: characters, positive integers and booleans. Each one of these can be either a single value, or an array of values of its type.
Characters
These are values that contain one character. These could be latin characters as well as sitelen pona glyphs.
Positive integers
Positive integers can be used in arithmatic, you can find more information in Number System
Booleans
Bolean values can only have two values:
or
These are equivalent to true and false respectively.
Converting between data types
To convert between characters and positive integers you can create a value similar to the one of the other type:
TYPEVARIABLE.
Once you have done this, you can refer to the converted value with
TYPE
TYPE
can be
or
to represent character or positive integer respectively.
Number system
The number system for representing positive integers uses the symbols
to represent values 100, 20, 5, 2 and 1 respectively. The way other numbers are constructed is simply through addition. For example
represents 100 + 5 + 5 + 2 or 112. Though for a number to be valid, it must be in descending order.
When doing arithmatic with positive numbers, if 0 or a negative number is reached, the value will simply become
which is similar to null in other programming languages.
Arithmatic
This is probably the area of toki pi ilo sona that strays the furthest away from toki pona. When programming, arithmatic is essential, and even when trying to maintain the basic number system. There is no standard way to do arithmatic in toki pona. Some of this has been inspired by a post by u/janPawato.
For now, I am going to use the Alternate arithmatic, but in the future this might become the main one as it is much more practical.
Addition and concatenation
FIRSTVALUESECONDVALUE
is (in my opinion) intuitively means concatinate (when working with strings or arrays) and add (when working with numbers). Using this with an a string and a number will result in the number being converted to a string representing it. Similarly, if an array and different value is used, the string or number will be converted to an array of length one containg the value.
Alternate arithmatic
This is an idea that might be slighly impractical, but I want to include and use it anyway as it does stay closer to grammaticaly correct toki pona! This arithmatic can be done by asking how many apples you would have in hypothetical situations:
Addition
FIRSTNUMBER, SECONDNUMBER, ?
If you have FIRSTNUMBER
apples and you get SECONDNUMBER
more apples, how many apples do you have?
Substraction
FIRSTNUMBER, SECONDNUMBER, ?
If you have FIRSTNUMBER
apples and you give SECONDNUMBER
apples away, how many apples do you have?
Multiplication
, FIRSTNUMBERSECONDNUMBER, ?
If you have any apples and you get FIRSTNUMBER
apples a SECONDNUMBER
number of times, how many apples do you have?
Division
FIRSTNUMBER, SECONDNUMBER?
If you have FIRSTNUMBER
, how many times can you give SECONDNUMBER
apples away?
Finally, to do something with this number you can refer to it as what the computer replied:
Note that this does not have to be used imediately after the question, it will simply hold the answer to the last question asked.
Boolean logic
Negation
To negate a boolean value, you can simply say that it is not that value:
BOOLVALUE
And and Or
These are simple operators, used intiuitively similar to Addition and concatenation. For and and or respectively, use
and
Output
When you want the computer to display text on the screen, you must tell it to do so with
VALUE. VARIABLE. : ARITHMATIC.
Input
To interact with the computer, it needs to come to have what you say:
.
Now, it is unlikely that you want to get user input without storing what this input is, to do so you can tell the computer to set this value to a variable with
: VARNAME.
Functions
Basic structure
All functions are algorithms or paths that the computer can take. They all follow the same basic structure:
FUNCNAME: ( ALGORITHM )
Calling the function is simply telling the computer to go along that path and thus can be done using
FUNCNAME.
Sending arguments
If you want to send arguments to a function, you simply tell the computer to go on that path by using these arguments:
FUNCNAMEFIRSTARGSECONDARG.
When you do this, the algorithm of the function gains access to these tools. You can refer to them based on the order they were sent with
ARGNUMBER
Note that the number must be written using the toki pona number system. Also, these arguments are not copies of the tools, they are the tools, and thus will be changed outside of the function when changed inside of the function. Similarly to passing arguments by reference in existing programming languages.
Returning a value
When you want to return a value from a function, you simply need to make sure that a variable is responsible for the function being followed. And in this scenario, returning a value is simply a case of telling the computer to leave the path it is on and to make the reason it was on that path in the first place be a different value:
FUNCNAME: ( ALGORITHM : VALUE. ) VARNAMEVARVALUE. VARNAMEFUNCNAME.
Obviously, you can simply tell the computer to abandon the path it is on without changing the variable’s value with
.
Note that, as the variable may not be set a value within the function, it must be defined before.
Conditional statements
Conditional statements are one of the core concepts of programming, without them you wouldn’t be able to do much. In toki pi ilo sona they follow a very similar structure to the common programming terms if and else.
If statements
The most basic form of a conditional statement is
CONDITION: ( ALGORITHM )
If you are familiar with toki pona, this should be very intuitive, the only difference with the spoken language is that we are able to group multiple things with the parenthasese.
Else if statements
If you wish to have code to be run in the case that the condition was not met you can use
FIRSTCONDITION: ( FIRSTALGORITHM ) : SECONDCONDITION: ( SECONDALGORITHM ) : ( THIRDALGORITHM )
With this structure, only one algorithm will run. If the first condition is true, the first algorithm will run, regardless of the other condition. If the first condition is false but the second one is true then the second algorithm will run. And finally, the third algorithm will only run in the case where both conditions are false.
Note that you can chain as many of the second statement as you wish and that only the first is necessary.
Conditions
There are three main conditions: equals, is greater than, is smaller than and the syntax for these is
FIRSTVALUESECONDVALUE
FIRSTVALUESECONDVALUE
FIRSTVALUESECONDVALUE
respectively.
Looping code
To loop code is similar to If statements. But you need to specify that it should cycle while the condition is true with
CONDITION: ( ALGORITHM )
Arrays
Arrays are groups of things. And I have yet to design syntax for them.
Examples
Here are some examples in toki pi ilo sona.
Classic 'Hello World!'
: ". !".
Check if a number is prime
: ( : ( . : ( , ? , , ? , , ? : ( : "". . ) , , ? . ) : "". ) : ( : "". ) ) . . .