Kana
- This is still a work in progress. It may be changed in the future.
Kana is a programming language created by User:LEOMOK. It is a prefix-notation language which uses Japanese kana symbols as instructions.
Literals
In Kana, there are four data types: numbers, strings, booleans and lists.
Numbers
Numbers can be integer or floating-point. They are created from the following digits:
| Digit | Value |
|---|---|
| 〇 | 0 |
| 一 | 1 |
| 二 | 2 |
| 三 | 3 |
| 四 | 4 |
| 五 | 5 |
| 六 | 6 |
| 七 | 7 |
| 八 | 8 |
| 九 | 9 |
A nonnegative integer is represented by a string of these digits, for example 157 is 一五七. To make a negative integer, insert 負 before the number (I know that in Japanese you can also use マイナス, but katakana characters are used for different purposes). Floats are written with 点 for the decimal point.
Strings
Strings of printable ASCII are written in the quotes 「」, with characters in these strings represented by characters in the Katakana Unicode block. To convert a printable ASCII character to a Kana character, add 0x30A0 to its character code than subtract 0x20. For example, the letter "A" (0x41) is represented as 0x41 + 0x30A0 - 0x20 = 0x30C1, which coressponds to the character チ. (The character ー (U+30FC, representing "|" in a string) is interchangeable with 一 (U+4E01, the digit 1).
In addition, a newline can be represented with 〜, and a tab with 〆.
There are also "raw strings" written in the quotes 『』, which represent the literal content inside the quotes. They are useful if your string contains non-printable ASCII characters.
Booleans
The characters 真 and 偽 are used for true and false, respectively.
Lists
Lists are represented by wrapping their contents in the delimiters 〔〕. Both 〔〕 and 空 represent the empty list.
Variables
There are 47 usable variables in Kana. They are represented with the following hiragana characters:
あ い う え お か き く け こ さ し す せ そ た ち つ て と な に ぬ ね の は ひ ふ ほ ま み む め も や ゆ よ ら り る れ ろ わ を ん ゐ ゑ
Each variable has an initial value of 0. You may also ゝ to refer to the return value of the last expression (it is 0 in the first expression). To make things easier, some of these values are pre-initialized to other values:
| Variable | Value |
|---|---|
| あ | First input value / function argument |
| い | Second input value / function argument |
| う | Third input value / function argument |
| え | Fourth input value / function argument |
| お | Fifth input value / function argument |
| ん | A list of all input variables / function arguments |
| や | Pi |
| ゆ | Tau (2 * pi) |
| よ | Euler's number |
| ら | ASCII uppercase alphabet A to Z, as string |
| り | ASCII lowercase alphabet a to z, as string |
| る | Digits 0 to 9, as string |
| れ | ASCII alphanumeric characters, as string |
| ろ | ASCII printable characters (U+0020 to U+007E), as string |
| わ | Regex to match a signed integer, /\-\d+/ |
| を | Regex to match a float, /\-\d+(\.\d+)?/ |
| ゐ | Regex to match an unsigned integer, /\d+/ |
| を | Regex to match any amount of whitespace, /\s*/ |
There is a special variable, ゟ, which is the seed of the random number generator used in the functions ヰ and ヱ.
Functions
The 48 katakana characters are used for functions.
When values are the incorrect type for a function, they are coerced as follows:
| Convert ↓ to → | Number | String | Boolean |
|---|---|---|---|
| Number | - | ASCII decimal representation | 0 → false, nonzero → true |
| String | Parse as ASCII decimal number (may error) | - | empty → false, nonempty → true |
| Boolean | true → 1, false → 0 | true → "true", false → "false" | - |
A list may be converted to a string, returning its values in brackets, separated with commas, with strings quoted and escaped, for example [1, 2, "text\n", [3, 4, true]], and to a boolean with empty lists becoming false and nonempty lists becoming true. However, converting a list into a number will raise an error.
When the type hint of an argument says "integer", an error will be raised if an argument is a noninteger.
When a function requires a regex to be expressed as a list, the list must contain exactly two values, both must be strings, which are the regex content and the flags, for example ["\-\d+(\.\d+)?", "gm"].
Here is what each of them do (all indexing is 0-based, negative indices count from the end like in Python):
| Function | Arguments | What it does |
|---|---|---|
| ア | number a, number b | Returns a + b. |
| イ | number a, number b | Returns a - b. |
| ウ | number a, number b | Returns a * b. |
| エ | number a, number b | Returns a / b. |
| オ | number a, number b | Returns a modulo b, with the sign of b. |
| カ | number a, number b | Returns a to the power of b. 0 to the power of 0 is 1. |
| キ | number a | Returns the absolute value of a. |
| ク | number a | Returns the floor of a. |
| ケ | number a | Returns the ceiling of a. |
| コ | number a | Returns a rounded to the nearest integer. |
| サ | string a, string b or: list a, list b |
Returns a concatenated to b. |
| シ | string/list a, integer b | Returns a repeated b times. If b is negative, returns an empty string. |
| ス | string/list a, integer b | Returns character/item at index b of a. |
| セ | string/list a, integer b, integer c | Returns characters/items at indices b through c of a, both ends inclusive. |
| ソ | string a, string b or: list a, any b |
Returns the index of b in a, -1 if not found. |
| タ | string a, string b | Split a using b as a delimiter. |
| チ | list a, string b | Convert all values in a to strings, then join them with b as a delimiter. |
| ツ | string a, string b, string c | Replace all instances of b with c in a. |
| テ | string a, string b, string c, integer d | Replace all instances of b with c in a, starting from index d. |
| ト | string a, string b, string c, integer d | Replace all instances of b with c in a, up to index d. |
| ナ | list a (all numbers or all strings) | Return the maximum value in a. |
| ニ | list a (all numbers or all strings) | Return the minimum value in a. |
| ヌ | list a (all numbers or all strings) | Return a sorted ascending. |
| ネ | string/list a | Return a reversed. |
| ノ | string/list a | Return a shuffled. |
| ハ | list a, any b | Return a with b added onto the end. |
| ヒ | list a, any b, integer c | Return a with b inserted at index c. |
| フ | list a, integer b | Return a with the value at index b deleted. |
| ヘ | list a, any b | Return a with the first instance of b deleted. |
| ホ | list a, any b | Return a with every instance of b deleted. |
| マ | string a, string a | Return whether a contains b, as a boolean. |
| ミ | string a, string a | Return whether a starts with b, as a boolean. |
| ム | string a, string a | Return whether a ends with b, as a boolean. |
| メ | string a | Convert a to uppercase. |
| モ | string a | Convert a to lowercase. |
| ヤ | number a, number b or: string a, string b |
Return whether a > b as a boolean. Strings are compared lexicographically in Unicode order. |
| ユ | number a, number b or: string a, string b |
Return whether a < b as a boolean. Strings are compared lexicographically in Unicode order. |
| ヨ | any a, any b |
Return whether a == b as a boolean. Two lists are equal if they have the same values in the same order. |
| ラ | string a, list b | Return a list of all matches of regex b on a. Returns an empty list if no matches. |
| リ | string a, list b | Split a by each match of regex b. |
| ル | string a, list b, string b | Replace every match of regex b in a with c. To reference a specific capture of the regex b in c, use:
|
| レ | string a | Return a list containing the Unicode values of each character of a. |
| ロ | list a (all numbers) | Return a string with the values in a as the codepoints. |
| ワ | boolean a, boolean b | Return a AND b, short-circuiting. |
| ヲ | boolean a, boolean b | Return a OR b, short-circuiting. |
| ン | boolean a | Return NOT a. |
| ヰ | number a, number b | Return a random integer between a and b, both ends inclusive. |
| ヱ | string/list a | Return a random value/character in a. |