User:Menasewi/toki ilo pona: Difference between revisions

m
no edit summary
(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]...")
 
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 1:
{{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|.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.
Line 13:
37 keywords and one alias are used:
 
<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:
Print:
 
{{Indent|<code>{{tok|o toki e ''[value]''}}</code>}}
 
 
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:
 
{{Indent|<code>{{tok|o toki e ''[value]'', e ''[value]''}}</code>}}
 
 
 
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:
Initialize or set a variable:
 
{{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.
Line 53:
==Values==
 
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>{{tok|ni}}</code>.
 
 
Line 61:
==Data types==
 
===<code>{{tok|lon}}</code>===
 
The <code>{{tok|lon}}</code> type stores a boolean. The boolean true is <code>{{tok|lon}}</code>.
 
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>{{tok|''[boolean]'' ala}}</code>.
 
The or operator is <code>{{tok|''[boolean]'' anu ''[boolean]''}}</code>.
 
 
 
===<code>{{tok|nanpa}}</code>===
 
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.
 
*<code>{{tok|ale}}</code> or <code>{{tok|ali}}</code>: 100
 
*<code>{{tok|mute}}</code>: 20
 
*<code>{{tok|luka}}</code>: 5
 
*<code>{{tok|tu}}</code>: 2
 
*<code>{{tok|wan}}</code>: 1
 
A negative number is formed with <code>{{tok|jasima}}</code> at the end.
 
 
 
An addend is formed with <code>{{tok|kin}}</code> after it. Increment a variable:
 
{{Indent|<code>{{tok|nanpa ''[Name]'' o wan kin}}</code>}}
 
Print the sum of 1 + 2:
 
{{Indent|<code>{{tok|o toki e ni: nanpa o wan, o tu kin}}</code>}}
 
(Out:{{Indent|<code>{{tok|tu wan}}</code>}})
 
 
 
A boolean is treated as a one-bit number. Cast a boolean to <code>{{tok|ala}}</code> or <code>{{tok|wan}}</code>:
 
{{Indent|<code>{{tok|nanpa ''[Name]'' o ''[boolean]''}}</code>}}
 
Casting a number to a boolean yields <code>{{tok|ala}}</code> if it is 0, and <code>{{tok|lon}}</code> otherwise.
 
 
 
===<code>{{tok|nimi}}</code>===
 
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>{{tok|kin}}</code> after it.
 
 
Line 125:
Hello, World!:
 
{{Indent|<code>{{tok|o toki e te toki, ma o!}}</code>}}
 
(Out:{{Indent|<code>{{tok|toki, ma o!}}</code>}})
 
 
Line 133:
Cast a boolean to its name:
 
{{Indent|<code>{{tok|nimi ''[Name]'' o ''[boolean]''}}</code>}}
 
Casting a string to a boolean yields <code>{{tok|ala}}</code> if it is empty, and <code>{{tok|lon}}</code> otherwise.
 
 
Line 141:
Cast a number to a string:
 
{{Indent|<code>{{tok|nimi ''[Name]'' o ''[number]''}}</code>}}
 
 
Line 149:
Character at position <var>i</var>:
 
{{Indent|<code>{{tok|nimi ''[Name]'' o ''[string]'' nanpa I}}</code>}}
 
 
 
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>{{tok|nanpa ''[Name]'' o ''[string]'' nanpa suli}}</code>}}
 
Penultimate character:
 
{{Indent|<code>{{tok|nimi ''[Name]'' o ''[string]'' ni: nanpa o suli, o wan jasima kin}}</code>}}
 
 
 
===<code>{{tok|pakala}}</code>===
 
<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>{{tok|pakala ''[Name]'' o ''[string]''}}</code>}}
 
{{Indent|<code>{{tok|o pakala ''[Name]''}}</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:
==Control flow==
 
Control flow uses <code>{{tok|la}}</code>.
 
 
Line 187:
If–else conditional:
 
{{Indent|<code>{{tok|''[condition]'' la}}</code>}}
 
{{Indent|{{Indent|<code>{{tok|''[then]''}}</code>}}}}
 
{{Indent|<code>{{tok|ante la}}</code>}}
 
{{Indent|{{Indent|<code>{{tok|''[else]''}}</code>}}}}
 
 
 
<code>{{tok|ni}}</code> cannot be used in the condition.
 
 
Line 205:
Values can only be compared in a condition.
 
={{Indent|<code>{{tok|''[value]'' li sama ''[value]'' la}}</code>}}
 
≠{{Indent|<code>{{tok|''[value]'' li sama ala ''[value]'' la}}</code>}}
 
<{{Indent|<code>{{tok|''[value]'' li lili tawa ''[value]'' la}}</code>}}
 
>{{Indent|<code>{{tok|''[value]'' li suli tawa ''[value]'' la}}</code>}}
 
≤{{Indent|<code>{{tok|''[value]'' li suli ala tawa ''[value]'' la}}</code>}}
 
≥{{Indent|<code>{{tok|''[value]'' li lili ala tawa ''[value]'' la}}</code>}}
 
 
Line 221:
===Loops===
 
<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:
The for loop can be implemented as a "while <var>i</var> meets a comparison" loop:
 
{{Indent|<code>{{tok|nanpa I o ''[min]''}}</code>}}
 
{{Indent|<code>{{tok|nanpa I li suli ala tawa ''[max]'' la}}</code>}}
 
{{Indent|{{Indent|<code>{{tok|''[commands]''}}</code>}}}}
 
{{Indent|{{Indent|<code>{{tok|nanpa I o wan kin}}</code>}}}}
 
{{Indent|{{Indent|<code>{{tok|o awen}}</code>}}}}
 
 
Line 241:
Infinite loop:
 
{{Indent|<code>{{tok|lon la}}</code>}}
 
{{Indent|{{Indent|<code>{{tok|''[commands]''}}</code>}}}}
 
{{Indent|{{Indent|<code>{{tok|o awen}}</code>}}}}
 
 
 
<code>{{tok|o weka·}}</code> breaks out of a block.
 
 
Line 257:
Function definition:
 
{{Indent|<code>{{tok|nasin ''[Name]'' kepeken ''[argument]'' la}}</code>}}
 
{{Indent|{{Indent|<code>{{tok|''[commands]''}}</code>}}}}
 
A function can have multiple arguments.
Line 269:
Invoke a function:
 
{{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.
Line 275:
 
 
<code>{{tok|''[value]'' o weka·}}</code> returns a value.
 
 
Line 283:
 
 
{{Indent|<code>{{tok|nasin Leko kepeken nanpa Tenpo, kepeken nanpa Suli, la}}</code>}}
 
{{Indent|{{Indent|<code>{{tok|lon Jasima o ala}}</code>}}}}
 
{{Indent|{{Indent|<code>{{tok|nanpa Tenpo li lili tawa ala la}}</code>}}}}
 
{{Indent|{{Indent|{{Indent|<code>{{tok|nanpa Tenpo o nanpa Tenpo jasima}}</code>}}}}}}
 
{{Indent|{{Indent|{{Indent|<code>{{tok|lon Jasima o lon}}</code>}}}}}}
 
{{Indent|{{Indent|<code>{{tok|nanpa Leko o ala}}</code>}}}}
 
{{Indent|{{Indent|<code>{{tok|nanpa Tenpo li suli tawa ala la}}</code>}}}}
 
{{Indent|{{Indent|{{Indent|<code>{{tok|nanpa Leko o nanpa Suli kin}}</code>}}}}}}
 
{{Indent|{{Indent|{{Indent|<code>{{tok|nanpa Tenpo o wan jasima kin}}</code>}}}}}}
 
{{Indent|{{Indent|{{Indent|<code>{{tok|o awen}}</code>}}}}}}
 
{{Indent|{{Indent|<code>{{tok|lon Jasima la}}</code>}}}}
 
{{Indent|{{Indent|{{Indent|<code>{{tok|nanpa Leko o nanpa Leko jasima}}</code>}}}}}}
 
{{Indent|{{Indent|<code>{{tok|nanpa Leko o weka}}</code>}}}}
 
 
 
{{Indent|<code>{{tok|o toki e ni: o nasin Leko e luka luka tu, e luka luka}}</code>}}
 
 
 
{{Indent|<code>{{tok|nasin Patowijo kepeken nanpa Suli la}}</code>}}
 
{{Indent|{{Indent|<code>{{tok|nanpa Suli li lili tawa ala la}}</code>}}}}
 
{{Indent|{{Indent|{{Indent|<code>{{tok|o pakala te nanpa Suli li ken ala lili tawa ala}}</code>}}}}}}
 
{{Indent|{{Indent|<code>{{tok|nanpa Suli li suli ala tawa wan la}}</code>}}}}
 
{{Indent|{{Indent|{{Indent|<code>{{tok|wan o weka}}</code>}}}}}}
 
{{Indent|{{Indent|<code>{{tok|nanpa Suli o wan jasima kin}}</code>}}}}
 
{{Indent|{{Indent|<code>{{tok|nanpa o nasin Leko e nanpa Suli, e ni, o weka:}}</code>}}}}
 
{{Indent|{{Indent|{{Indent|<code>{{tok|o nasin Patowijo e nanpa Suli}}</code>}}}}}}
 
 
 
{{Indent|<code>{{tok|o toki e ni: o nasin Patowijo e luka}}</code>}}
 
 
 
(Out:{{Indent|<code>{{tok|ale mute}}</code>}}
 
{{Indent|<code>{{tok|ale mute}}</code>}})