User:Menasewi/toki ilo pona: Difference between revisions

Content added Content deleted
(Created page with "{{Hatnote|This page is a copy of a [//docs.google.com/document/d/1NejN53Xu3a0e49OFylMg4Y5tzEvF_0kqMt2oYtQuMxA/preview Google Doc], with links added.}} {{tok|toki ilo pona}} (<code>.tok</code>) is a programming language. It was designed by {{tok|kulupu Menasewi}} on August 14, 2023. It is based on Toki Pona, a constructed human language by Sonja Lang. It takes inspiration from prior art on the wiki Esolang, mainly {{tok|[[toki pi ilo nanpa]...")
 
No edit summary
Line 1: Line 1:
{{Hatnote|This page is a copy of a [//docs.google.com/document/d/1NejN53Xu3a0e49OFylMg4Y5tzEvF_0kqMt2oYtQuMxA/preview Google Doc], with links added.}}
{{tok title|toki ilo pona}}{{Hatnote|This page is a copy of a [//docs.google.com/document/d/1NejN53Xu3a0e49OFylMg4Y5tzEvF_0kqMt2oYtQuMxA/preview Google Doc], with links added.}}


{{tok|toki ilo pona}} (<code>.tok</code>) is a [[programming language]]. It was designed by [[User:Menasewi|{{tok|kulupu Menasewi}}]] on August 14, 2023.
{{tok|toki ilo pona}} (<code>{{tok|.tok}}</code>) is a [[programming language]]. It was designed by [[User:Menasewi|{{tok|kulupu Menasewi}}]] on August 14, 2023.


It is based on [[Toki Pona]], a constructed human language by [[Sonja Lang]]. It takes inspiration from prior art on the wiki Esolang, mainly {{tok|[[toki pi ilo nanpa]]}}, while trying to be closer to the spirit of Toki Pona.
It is based on [[Toki Pona]], a constructed human language by [[Sonja Lang]]. It takes inspiration from prior art on the wiki Esolang, mainly {{tok|[[toki pi ilo nanpa]]}}, while trying to be closer to the spirit of Toki Pona.
Line 13: Line 13:
37 keywords and one alias are used:
37 keywords and one alias are used:


<code>[[ala|{{tok|ala}}]] [[ale|{{tok|ale}}]]~[[ali|{{tok|ali}}]] [[ante|{{tok|ante}}]] [[anu|{{tok|anu}}]] [[awen|{{tok|awen}}]] [[e|{{tok|e}}]] [[jasima|{{tok|jasima}}]] [[kepeken|{{tok|kepeken}}]] [[la|{{tok|la}}]] [[li|{{tok|li}}]] [[lili|{{tok|lili}}]] [[lon|{{tok|lon}}]] [[luka|{{tok|luka}}]] [[mute|{{tok|mute}}]] [[nanpa|{{tok|nanpa}}]] [[ni|{{tok|ni}}]] [[nimi|{{tok|nimi}}]] [[o|{{tok|o}}]] [[pakala|{{tok|pakala}}]] [[kin|{{tok|kin}}]] [[suli|{{tok|suli}}]] [[te|{{tok|te}}]] [[to|{{tok|to}}]] [[toki|{{tok|toki}}]] [[tu|{{tok|tu}}]] [[wan|{{tok|wan}}]] [[weka|{{tok|weka}}]]</code>
<code>{{tok|[[ala|{{tok|ala}}]] [[ale|{{tok|ale}}]]~[[ali|{{tok|ali}}]] [[ante|{{tok|ante}}]] [[anu|{{tok|anu}}]] [[awen|{{tok|awen}}]] [[e|{{tok|e}}]] [[jasima|{{tok|jasima}}]] [[kepeken|{{tok|kepeken}}]] [[la|{{tok|la}}]] [[li|{{tok|li}}]] [[lili|{{tok|lili}}]] [[lon|{{tok|lon}}]] [[luka|{{tok|luka}}]] [[mute|{{tok|mute}}]] [[nanpa|{{tok|nanpa}}]] [[ni|{{tok|ni}}]] [[nimi|{{tok|nimi}}]] [[o|{{tok|o}}]] [[pakala|{{tok|pakala}}]] [[kin|{{tok|kin}}]] [[suli|{{tok|suli}}]] [[te|{{tok|te}}]] [[to|{{tok|to}}]] [[toki|{{tok|toki}}]] [[tu|{{tok|tu}}]] [[wan|{{tok|wan}}]] [[weka|{{tok|weka}}]]}}</code>




Line 25: Line 25:
Print:
Print:


{{Indent|<code>o toki e ''[value]''</code>}}
{{Indent|<code>{{tok|o toki e ''[value]''}}</code>}}




Line 31: Line 31:
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:
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:


{{Indent|<code>o toki e ''[value]'', e ''[value]''</code>}}
{{Indent|<code>{{tok|o toki e ''[value]'', e ''[value]''}}</code>}}






Commands are heavily limited in their syntax, but most can be joined. <code>ni</code> references the subject of the following command, which is run first. (In Latin text, it is conventional to end <code>ni</code> commands with a colon.)
Commands are heavily limited in their syntax, but most can be joined. <code>{{tok|ni}}</code> references the subject of the following command, which is run first. (In Latin text, it is conventional to end <code>{{tok|ni}}</code> commands with a colon.)




Line 43: Line 43:
Initialize or set a variable:
Initialize or set a variable:


{{Indent|<code>''[type]'' ''[Name]'' o ''[value]''</code>}}
{{Indent|<code>{{tok|''[type]'' ''[Name]'' o ''[value]''}}</code>}}


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 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.
Line 53: Line 53:
==Values==
==Values==


A value can be preceded by its type with no change in meaning. For a numeric example, <code>ala</code> is equivalent to <code>nanpa ala</code>.
A value can be preceded by its type with no change in meaning. For a numeric example, <code>{{tok|ala}}</code> is equivalent to <code>{{tok|nanpa ala}}</code>.


If the name is excluded from a variable declaration, the command will serve as a temporary value that can be substituted back into <code>ni</code>.
If the name is excluded from a variable declaration, the command will serve as a temporary value that can be substituted back into <code>{{tok|ni}}</code>.




Line 61: Line 61:
==Data types==
==Data types==


===<code>lon</code>===
===<code>{{tok|lon}}</code>===


The <code>lon</code> type stores a boolean. The boolean true is <code>lon</code>.
The <code>{{tok|lon}}</code> type stores a boolean. The boolean true is <code>{{tok|lon}}</code>.


The boolean false is <code>ala</code>. Because a value can be preceded by its type, <code>lon ala</code> also works.
The boolean false is <code>{{tok|ala}}</code>. Because a value can be preceded by its type, <code>{{tok|lon ala}}</code> also works.






The not operator is <code>''[boolean]'' ala</code>.
The not operator is <code>{{tok|''[boolean]'' ala}}</code>.


The or operator is <code>''[boolean]'' anu ''[boolean]''</code>.
The or operator is <code>{{tok|''[boolean]'' anu ''[boolean]''}}</code>.






===<code>nanpa</code>===
===<code>{{tok|nanpa}}</code>===


The <code>nanpa</code> type stores an integer. <code>ala</code> is 0.
The <code>{{tok|nanpa}}</code> type stores an integer. <code>{{tok|ala}}</code> is 0.


Other integers are formed with Toki Pona [[numerals]], additive from highest to lowest value.
Other integers are formed with Toki Pona [[numerals]], additive from highest to lowest value.


*<code>ale</code> or <code>ali</code>: 100
*<code>{{tok|ale}}</code> or <code>{{tok|ali}}</code>: 100


*<code>mute</code>: 20
*<code>{{tok|mute}}</code>: 20


*<code>luka</code>: 5
*<code>{{tok|luka}}</code>: 5


*<code>tu</code>: 2
*<code>{{tok|tu}}</code>: 2


*<code>wan</code>: 1
*<code>{{tok|wan}}</code>: 1


A negative number is formed with <code>jasima</code> at the end.
A negative number is formed with <code>{{tok|jasima}}</code> at the end.






An addend is formed with <code>kin</code> after it. Increment a variable:
An addend is formed with <code>{{tok|kin}}</code> after it. Increment a variable:


{{Indent|<code>nanpa ''[Name]'' o wan kin</code>}}
{{Indent|<code>{{tok|nanpa ''[Name]'' o wan kin}}</code>}}


Print the sum of 1 + 2:
Print the sum of 1 + 2:


{{Indent|<code>o toki e ni: nanpa o wan, o tu kin</code>}}
{{Indent|<code>{{tok|o toki e ni: nanpa o wan, o tu kin}}</code>}}


(Out:{{Indent|<code>tu wan</code>}})
(Out:{{Indent|<code>{{tok|tu wan}}</code>}})




Line 109: Line 109:
A boolean is treated as a one-bit number. Cast a boolean to ala or wan:
A boolean is treated as a one-bit number. Cast a boolean to ala or wan:


{{Indent|<code>nanpa ''[Name]'' o ''[boolean]''</code>}}
{{Indent|<code>{{tok|nanpa ''[Name]'' o ''[boolean]''}}</code>}}


Casting a number to a boolean yields <code>ala</code> if it is 0, and <code>lon</code> otherwise.
Casting a number to a boolean yields <code>{{tok|ala}}</code> if it is 0, and <code>{{tok|lon}}</code> otherwise.






===<code>nimi</code>===
===<code>{{tok|nimi}}</code>===


The <code>nimi</code> type stores a string. Strings are delimited with <code>te … to</code>. Outer whitespace is trimmed. If the string continues to the end of the line, the <code>to</code> can be dropped.
The <code>{{tok|nimi}}</code> type stores a string. Strings are delimited with <code>{{tok|te … to}}</code>. Outer whitespace is trimmed. If the string continues to the end of the line, the <code>{{tok|to}}</code> can be dropped.


A string that concatenates onto a previous one is formed with <code>kin</code> after it.
A string that concatenates onto a previous one is formed with <code>{{tok|kin}}</code> after it.




Line 125: Line 125:
Hello, World!:
Hello, World!:


{{Indent|<code>o toki e te toki, ma o!</code>}}
{{Indent|<code>{{tok|o toki e te toki, ma o!}}</code>}}


(Out:{{Indent|<code>toki, ma o!</code>}})
(Out:{{Indent|<code>{{tok|toki, ma o!}}</code>}})




Line 133: Line 133:
Cast a boolean to its name:
Cast a boolean to its name:


{{Indent|<code>nimi ''[Name]'' o ''[boolean]''</code>}}
{{Indent|<code>{{tok|nimi ''[Name]'' o ''[boolean]''}}</code>}}


Casting a string to a boolean yields <code>ala</code> if it is empty, and <code>lon</code> otherwise.
Casting a string to a boolean yields <code>{{tok|ala}}</code> if it is empty, and <code>{{tok|lon}}</code> otherwise.




Line 141: Line 141:
Cast a number to a string:
Cast a number to a string:


{{Indent|<code>nimi ''[Name]'' o ''[number]''</code>}}
{{Indent|<code>{{tok|nimi ''[Name]'' o ''[number]''}}</code>}}




Line 149: Line 149:
Character at position <var>i</var>:
Character at position <var>i</var>:


{{Indent|<code>nimi ''[Name]'' o ''[string]'' nanpa I</code>}}
{{Indent|<code>{{tok|nimi ''[Name]'' o ''[string]'' nanpa I}}</code>}}






Here, <code>suli</code> 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:
Here, <code>{{tok|suli}}</code> 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:


{{Indent|<code>nanpa ''[Name]'' o ''[string]'' nanpa suli</code>}}
{{Indent|<code>{{tok|nanpa ''[Name]'' o ''[string]'' nanpa suli}}</code>}}


Penultimate character:
Penultimate character:


{{Indent|<code>nimi ''[Name]'' o ''[string]'' ni: nanpa o suli, o wan jasima kin</code>}}
{{Indent|<code>{{tok|nimi ''[Name]'' o ''[string]'' ni: nanpa o suli, o wan jasima kin}}</code>}}






===<code>pakala</code>===
===<code>{{tok|pakala}}</code>===


<code>pakala</code> 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:
<code>{{tok|pakala}}</code> 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:


{{Indent|<code>pakala ''[Name]'' o ''[string]''</code>}}
{{Indent|<code>{{tok|pakala ''[Name]'' o ''[string]''}}</code>}}


{{Indent|<code>o pakala ''[Name]''</code>}}
{{Indent|<code>{{tok|o pakala ''[Name]''}}</code>}}






Built-in commands also use <code>pakala</code>. For example, if a string that does not represent a number is cast to a number, it throws <code>pakala</code>.
Built-in commands also use <code>{{tok|pakala}}</code>. For example, if a string that does not represent a number is cast to a number, it throws <code>{{tok|pakala}}</code>.




Line 179: Line 179:
==Control flow==
==Control flow==


Control flow uses <code>la</code>.
Control flow uses <code>{{tok|la}}</code>.




Line 187: Line 187:
If–else conditional:
If–else conditional:


{{Indent|<code>''[condition]'' la</code>}}
{{Indent|<code>{{tok|''[condition]'' la}}</code>}}


{{Indent|{{Indent|<code>''[then]''</code>}}}}
{{Indent|{{Indent|<code>{{tok|''[then]''}}</code>}}}}


{{Indent|<code>ante la</code>}}
{{Indent|<code>{{tok|ante la}}</code>}}


{{Indent|{{Indent|<code>''[else]''</code>}}}}
{{Indent|{{Indent|<code>{{tok|''[else]''}}</code>}}}}






<code>ni</code> cannot be used in the condition.
<code>{{tok|ni}}</code> cannot be used in the condition.




Line 205: Line 205:
Values can only be compared in a condition.
Values can only be compared in a condition.


={{Indent|<code>''[value]'' li sama ''[value]'' la</code>}}
={{Indent|<code>{{tok|''[value]'' li sama ''[value]'' la}}</code>}}


≠{{Indent|<code>''[value]'' li sama ala ''[value]'' la</code>}}
≠{{Indent|<code>{{tok|''[value]'' li sama ala ''[value]'' la}}</code>}}


<{{Indent|<code>''[value]'' li lili tawa ''[value]'' la</code>}}
<{{Indent|<code>{{tok|''[value]'' li lili tawa ''[value]'' la}}</code>}}


>{{Indent|<code>''[value]'' li suli tawa ''[value]'' la</code>}}
>{{Indent|<code>{{tok|''[value]'' li suli tawa ''[value]'' la}}</code>}}


≤{{Indent|<code>''[value]'' li suli ala tawa ''[value]'' la</code>}}
≤{{Indent|<code>{{tok|''[value]'' li suli ala tawa ''[value]'' la}}</code>}}


≥{{Indent|<code>''[value]'' li lili ala tawa ''[value]'' la</code>}}
≥{{Indent|<code>{{tok|''[value]'' li lili ala tawa ''[value]'' la}}</code>}}




Line 221: Line 221:
===Loops===
===Loops===


<code>o awen·</code> loops from the head of the latest block. It retries the condition, then continues down the corresponding branch.
<code>{{tok|o awen·}}</code> loops from the head of the latest block. It retries the condition, then continues down the corresponding branch.




Line 227: Line 227:
The for loop can be implemented as a "while <var>i</var> meets a comparison" loop:
The for loop can be implemented as a "while <var>i</var> meets a comparison" loop:


{{Indent|<code>nanpa I o ''[min]''</code>}}
{{Indent|<code>{{tok|nanpa I o ''[min]''}}</code>}}


{{Indent|<code>nanpa I li suli ala tawa ''[max]'' la</code>}}
{{Indent|<code>{{tok|nanpa I li suli ala tawa ''[max]'' la}}</code>}}


{{Indent|{{Indent|<code>''[commands]''</code>}}}}
{{Indent|{{Indent|<code>{{tok|''[commands]''}}</code>}}}}


{{Indent|{{Indent|<code>nanpa I o wan kin</code>}}}}
{{Indent|{{Indent|<code>{{tok|nanpa I o wan kin}}</code>}}}}


{{Indent|{{Indent|<code>o awen</code>}}}}
{{Indent|{{Indent|<code>{{tok|o awen}}</code>}}}}




Line 241: Line 241:
Infinite loop:
Infinite loop:


{{Indent|<code>lon la</code>}}
{{Indent|<code>{{tok|lon la}}</code>}}


{{Indent|{{Indent|<code>''[commands]''</code>}}}}
{{Indent|{{Indent|<code>{{tok|''[commands]''}}</code>}}}}


{{Indent|{{Indent|<code>o awen</code>}}}}
{{Indent|{{Indent|<code>{{tok|o awen}}</code>}}}}






<code>o weka·</code> breaks out of a block.
<code>{{tok|o weka·}}</code> breaks out of a block.




Line 257: Line 257:
Function definition:
Function definition:


{{Indent|<code>nasin ''[Name]'' kepeken ''[argument]'' la</code>}}
{{Indent|<code>{{tok|nasin ''[Name]'' kepeken ''[argument]'' la}}</code>}}


{{Indent|{{Indent|<code>''[commands]''</code>}}}}
{{Indent|{{Indent|<code>{{tok|''[commands]''}}</code>}}}}


A function can have multiple arguments.
A function can have multiple arguments.
Line 269: Line 269:
Invoke a function:
Invoke a function:


{{Indent|<code>o nasin ''[Name]'' e ''[argument]''</code>}}
{{Indent|<code>{{tok|o nasin ''[Name]'' e ''[argument]''}}</code>}}


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.
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.
Line 275: Line 275:




<code>''[value]'' o weka·</code> returns a value.
<code>{{tok|''[value]'' o weka·}}</code> returns a value.




Line 283: Line 283:




{{Indent|<code>nasin Leko kepeken nanpa Tenpo, kepeken nanpa Suli, la</code>}}
{{Indent|<code>{{tok|nasin Leko kepeken nanpa Tenpo, kepeken nanpa Suli, la}}</code>}}


{{Indent|{{Indent|<code>lon Jasima o ala</code>}}}}
{{Indent|{{Indent|<code>{{tok|lon Jasima o ala}}</code>}}}}


{{Indent|{{Indent|<code>nanpa Tenpo li lili tawa ala la</code>}}}}
{{Indent|{{Indent|<code>{{tok|nanpa Tenpo li lili tawa ala la}}</code>}}}}


{{Indent|{{Indent|{{Indent|<code>nanpa Tenpo o nanpa Tenpo jasima</code>}}}}}}
{{Indent|{{Indent|{{Indent|<code>{{tok|nanpa Tenpo o nanpa Tenpo jasima}}</code>}}}}}}


{{Indent|{{Indent|{{Indent|<code>lon Jasima o lon</code>}}}}}}
{{Indent|{{Indent|{{Indent|<code>{{tok|lon Jasima o lon}}</code>}}}}}}


{{Indent|{{Indent|<code>nanpa Leko o ala</code>}}}}
{{Indent|{{Indent|<code>{{tok|nanpa Leko o ala}}</code>}}}}


{{Indent|{{Indent|<code>nanpa Tenpo li suli tawa ala la</code>}}}}
{{Indent|{{Indent|<code>{{tok|nanpa Tenpo li suli tawa ala la}}</code>}}}}


{{Indent|{{Indent|{{Indent|<code>nanpa Leko o nanpa Suli kin</code>}}}}}}
{{Indent|{{Indent|{{Indent|<code>{{tok|nanpa Leko o nanpa Suli kin}}</code>}}}}}}


{{Indent|{{Indent|{{Indent|<code>nanpa Tenpo o wan jasima kin</code>}}}}}}
{{Indent|{{Indent|{{Indent|<code>{{tok|nanpa Tenpo o wan jasima kin}}</code>}}}}}}


{{Indent|{{Indent|{{Indent|<code>o awen</code>}}}}}}
{{Indent|{{Indent|{{Indent|<code>{{tok|o awen}}</code>}}}}}}


{{Indent|{{Indent|<code>lon Jasima la</code>}}}}
{{Indent|{{Indent|<code>{{tok|lon Jasima la}}</code>}}}}


{{Indent|{{Indent|{{Indent|<code>nanpa Leko o nanpa Leko jasima</code>}}}}}}
{{Indent|{{Indent|{{Indent|<code>{{tok|nanpa Leko o nanpa Leko jasima}}</code>}}}}}}


{{Indent|{{Indent|<code>nanpa Leko o weka</code>}}}}
{{Indent|{{Indent|<code>{{tok|nanpa Leko o weka}}</code>}}}}






{{Indent|<code>o toki e ni: o nasin Leko e luka luka tu, e luka luka</code>}}
{{Indent|<code>{{tok|o toki e ni: o nasin Leko e luka luka tu, e luka luka}}</code>}}






{{Indent|<code>nasin Patowijo kepeken nanpa Suli la</code>}}
{{Indent|<code>{{tok|nasin Patowijo kepeken nanpa Suli la}}</code>}}


{{Indent|{{Indent|<code>nanpa Suli li lili tawa ala la</code>}}}}
{{Indent|{{Indent|<code>{{tok|nanpa Suli li lili tawa ala la}}</code>}}}}


{{Indent|{{Indent|{{Indent|<code>o pakala te nanpa Suli li ken ala lili tawa ala</code>}}}}}}
{{Indent|{{Indent|{{Indent|<code>{{tok|o pakala te nanpa Suli li ken ala lili tawa ala}}</code>}}}}}}


{{Indent|{{Indent|<code>nanpa Suli li suli ala tawa wan la</code>}}}}
{{Indent|{{Indent|<code>{{tok|nanpa Suli li suli ala tawa wan la}}</code>}}}}


{{Indent|{{Indent|{{Indent|<code>wan o weka</code>}}}}}}
{{Indent|{{Indent|{{Indent|<code>{{tok|wan o weka}}</code>}}}}}}


{{Indent|{{Indent|<code>nanpa Suli o wan jasima kin</code>}}}}
{{Indent|{{Indent|<code>{{tok|nanpa Suli o wan jasima kin}}</code>}}}}


{{Indent|{{Indent|<code>nanpa o nasin Leko e nanpa Suli, e ni, o weka:</code>}}}}
{{Indent|{{Indent|<code>{{tok|nanpa o nasin Leko e nanpa Suli, e ni, o weka:}}</code>}}}}


{{Indent|{{Indent|{{Indent|<code>o nasin Patowijo e nanpa Suli</code>}}}}}}
{{Indent|{{Indent|{{Indent|<code>{{tok|o nasin Patowijo e nanpa Suli}}</code>}}}}}}






{{Indent|<code>o toki e ni: o nasin Patowijo e luka</code>}}
{{Indent|<code>{{tok|o toki e ni: o nasin Patowijo e luka}}</code>}}






(Out:{{Indent|<code>ale mute</code>}}
(Out:{{Indent|<code>{{tok|ale mute}}</code>}}


{{Indent|<code>ale mute</code>}})
{{Indent|<code>{{tok|ale mute}}</code>}})