Sakura
A recreational programming language designed to be concise.
Turing complete: unknown · ●●○ moderate
Tested with 7 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Sakura is a golfing language whose interpreter, in Ruby, lives in the Try It Online organisation on GitHub. A program is written in Polish notation. Every command knows how many arguments it takes, so +2³ needs no brackets and no spaces, as the + takes the next two expressions. Because two numbers would run together, the second one is written in superscript digits.
Read the story
A line that ends before its commands have all their arguments fills the gaps itself, with ⓪, ① and so on, the arguments the line was called with. So a line can be a function, and L calls another line by its number. The value of the last expression on line 0 is printed at the end.
The machine
| Command | Does |
|---|---|
12, ³⁴, [...], ⟪text⟫, 'c | Numbers, a second number, a list, a string, one character |
H | The string Hello, World! |
+ - * ÷ % | Arithmetic, item by item over lists |
= < > | Comparisons, -1 for true and 0 for false |
R r Σ ŋ J j | Ranges, sum, reverse, join |
M S C | Map, select and reduce, with the item as ⓪ |
I E W | If, if-else, while |
⓪ ① ₀ ₉ | An argument; an item of a list, ₉ the last |
L ‹ › ₡ | Run a line with arguments, by number, the one before, after, or this one |
Ꝇ ꝇ | Read a line, print a value |
The full language has over a hundred commands, many of them single symbols from its own code page. This implementation has the core above and stops with a reason on the rest.
Example
The fourth maps the range 1 to 5 to its squares.
The fourth maps the range 1 to 5 to its squares. In the last, line 0 calls line 1 with the argument 10, and line 1 multiplies its first argument by itself.
Patterns it teaches
- Code golf: fixed arities take the place of brackets, and superscripts take the place of spaces.
- Encoding tricks: the source is written in a single-byte code page of its own, so every symbol costs one byte.
Try this
- Print the product of the numbers 1 to 6.
- Print the even numbers up to 20.
- Hard: a line that calls itself to count down from 5.
Further
- The reference interpreter, in Ruby
See also
Also in Golfing
Write your own in Run Convert a program from Sakura
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: sakura.
Command line
shib run sakura -e 'H'shib manual sakuraSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/sakura.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language