esolang

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

Expected: Hello, World!

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

CommandDoes
12, ³⁴, [...], ⟪text⟫, 'cNumbers, a second number, a list, a string, one character
HThe string Hello, World!
+ - * ÷ %Arithmetic, item by item over lists
= < >Comparisons, -1 for true and 0 for false
R r Σ ŋ J jRanges, sum, reverse, join
M S CMap, select and reduce, with the item as ⓪
I E WIf, 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.
Expected: 5
Expected: 15
Expected: [1, 4, 9, 16, 25]
Expected: 100

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

  1. Print the product of the numbers 1 to 6.
  2. Print the even numbers up to 20.
  3. Hard: a line that calls itself to count down from 5.

Further

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 sakura

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/sakura.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language