We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

πŸ‰πŸ‰πŸ‰πŸŒπŸŒπŸŒπŸπŸπŸ

From Esolang
Jump to navigation Jump to search

πŸ‰πŸ‰πŸ‰πŸŒπŸŒπŸŒπŸπŸπŸ (read aloud: "three watermelons, three bananas, three pineapples"; informally Triple Salad) is an esoteric programming language written with exactly three symbols: πŸ‰, 🍌 and 🍍. Every instruction is a triplet of fruits: the first two fruits choose a verb, the third fruit chooses one of three stacks ("baskets") to act on.

Overview

Fruits are read as ternary digits: πŸ‰ = 0, 🍌 = 1, 🍍 = 2. All other characters are comments. The fruits are grouped into triplets from the start of the program, so the total number of fruits must be a multiple of 3.

A triplet abc means: verb number = 3Β·a + b (one of 9 verbs), basket = c.

Memory

There are three baskets, named after their fruit: A = πŸ‰, B = 🍌, C = 🍍. Each basket is an unbounded stack of unbounded signed integers with an infinite supply of zeros underneath. The "top" of an empty basket is 0.

The baskets are arranged in a ring: πŸ‰ β†’ 🍌 β†’ 🍍 β†’ πŸ‰. next(X) is the following basket in the ring, prev(X) is the preceding one.

Instructions

X is the basket given by the third fruit of the triplet.

Verb Name Effect Triplets (X = A / B / C)
πŸ‰πŸ‰ INC top(X) += 1 πŸ‰πŸ‰πŸ‰ / πŸ‰πŸ‰πŸŒ / πŸ‰πŸ‰πŸ
πŸ‰πŸŒ DEC top(X) -= 1 πŸ‰πŸŒπŸ‰ / πŸ‰πŸŒπŸŒ / πŸ‰πŸŒπŸ
πŸ‰πŸ OUT Print the Unicode character whose code point is top(X) (invalid values print U+FFFD). Does not pop. πŸ‰πŸπŸ‰ / πŸ‰πŸπŸŒ / πŸ‰πŸπŸ
πŸŒπŸ‰ OPEN If top(X) = 0, jump past the matching CLOSE. πŸŒπŸ‰πŸ‰ / πŸŒπŸ‰πŸŒ / πŸŒπŸ‰πŸ
🍌🍌 IN Read one Unicode character and replace top(X) with its code point (0 on EOF). πŸŒπŸŒπŸ‰ / 🍌🍌🍌 / 🍌🍌🍍
🍌🍍 CLOSE If top(X) β‰  0, jump back to the instruction right after the matching OPEN. πŸŒπŸπŸ‰ / 🍌🍍🍌 / 🍌🍍🍍
πŸπŸ‰ MOVEβ†’ Pop X and push the value onto next(X). πŸπŸ‰πŸ‰ / πŸπŸ‰πŸŒ / πŸπŸ‰πŸ
🍍🍌 MOVE← Pop X and push the value onto prev(X). πŸπŸŒπŸ‰ / 🍍🍌🍌 / 🍍🍌🍍
🍍🍍 COPY Push a copy of top(X) onto next(X). πŸπŸπŸ‰ / 🍍🍍🍌 / 🍍🍍🍍

Mnemonic: πŸ‰ handles numbers (and "spits seeds", i.e. output), 🍌 bends the control flow and bites input, 🍍 moves things between baskets.

Notes

  • OPEN and CLOSE are matched like brackets. An unmatched one is a syntax error.
  • The baskets named by an OPEN and its CLOSE need not be the same. Since CLOSE jumps to just after OPEN, the OPEN test is only performed when the loop is entered.
  • Popping an empty basket yields 0 (no error). INC, DEC and IN on an empty basket first create a zero.
  • Integers never wrap around.

The name

The name is itself a valid program: πŸ‰πŸ‰πŸ‰ is INC A, 🍌🍌🍌 is IN B, 🍍🍍🍍 is COPY C (onto A). It has no visible output.

Computational class

The language is Turing complete by a direct translation from Brainfuck. The tape is stored in two baskets: the current cell is top(A), cells to the left lie beneath it in A, and cells to the right are in B (nearest on top). Basket C is left over as free scratch space.

Brainfuck πŸ‰πŸŒπŸ Brainfuck πŸ‰πŸŒπŸ
+ πŸ‰πŸ‰πŸ‰ [ πŸŒπŸ‰πŸ‰
- πŸ‰πŸŒπŸ‰ ] πŸŒπŸπŸ‰
. πŸ‰πŸπŸ‰ > 🍍🍌🍌
, πŸŒπŸŒπŸ‰ < πŸπŸ‰‰πŸ‰

(Cells do not wrap, so Brainfuck programs that rely on 8-bit wrap-around need adapting.)

Examples

Hello, World!

Mechanical translation of the well-known Brainfuck program (prints "Hello World!" and a newline). Line breaks are only for readability.

πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰
πŸŒπŸ‰πŸ‰πŸπŸŒπŸŒπŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸπŸŒπŸŒ
πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸπŸŒπŸŒπŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸπŸŒπŸŒπŸ‰πŸ‰πŸ‰
πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸπŸŒπŸŒπŸ‰πŸ‰πŸ‰πŸπŸ‰πŸ‰πŸπŸ‰πŸ‰πŸπŸ‰πŸ‰πŸπŸ‰πŸ‰
πŸ‰πŸŒπŸ‰πŸŒπŸπŸ‰πŸπŸŒπŸŒπŸ‰πŸ‰πŸ‰πŸπŸŒπŸŒπŸ‰πŸ‰πŸ‰πŸπŸŒπŸŒπŸ‰πŸŒπŸ‰
πŸπŸŒπŸŒπŸπŸŒπŸŒπŸ‰πŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸπŸ‰πŸ‰πŸŒπŸπŸ‰πŸπŸ‰πŸ‰πŸ‰πŸŒπŸ‰
πŸŒπŸπŸ‰πŸπŸŒπŸŒπŸπŸŒπŸŒπŸ‰πŸπŸ‰πŸπŸŒπŸŒπŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰
πŸ‰πŸπŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰
πŸ‰πŸπŸ‰πŸ‰πŸπŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸπŸ‰πŸπŸŒπŸŒπŸπŸŒπŸŒ
πŸ‰πŸπŸ‰πŸπŸ‰πŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸπŸ‰πŸπŸ‰πŸ‰πŸ‰πŸπŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰
πŸ‰πŸ‰πŸ‰πŸ‰πŸπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰
πŸ‰πŸπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰πŸ‰πŸŒπŸ‰
πŸ‰πŸŒπŸ‰πŸ‰πŸπŸ‰πŸπŸŒπŸŒπŸπŸŒπŸŒπŸ‰πŸ‰πŸ‰πŸ‰πŸπŸ‰πŸπŸŒπŸŒπŸ‰πŸ‰πŸ‰
πŸ‰πŸ‰πŸ‰πŸ‰πŸπŸ‰

Cat

Copies input to output (until EOF or a NUL character).

πŸŒπŸŒπŸ‰   # IN A
πŸŒπŸ‰πŸ‰‰   # OPEN A
πŸ‰πŸπŸ‰   #   OUT A
πŸŒπŸŒπŸ‰   #   IN A
πŸŒπŸπŸ‰   # CLOSE A

Reverse

Reverses its input, using basket B as a stack.

πŸŒπŸŒπŸ‰   # IN A          read first character
πŸŒπŸ‰πŸ‰   # OPEN A        while it is not 0:
πŸπŸ‰πŸ‰   #   MOVEβ†’ A     push it onto B
πŸŒπŸŒπŸ‰   #   IN A        read the next character
πŸŒπŸπŸ‰   # CLOSE A
πŸŒπŸ‰πŸŒ   # OPEN B        while top(B) is not 0:
πŸ‰πŸπŸŒ   #   OUT B       print it
πŸπŸ‰πŸŒ   #   MOVEβ†’ B     pop it (into C)
🍌🍍🍌   # CLOSE B

For example, the input abc ΠŸΡ€ΠΈΠ²Π΅Ρ‚ produces Ρ‚Π΅Π²ΠΈΡ€ΠŸ cba.

Implementation

A reference interpreter in Python 3 (run as python3 fruit.py program.txt):

import sys

FRUITS = {"πŸ‰": 0, "🍌": 1, "🍍": 2}

def parse(src):
    f = [FRUITS[c] for c in src if c in FRUITS]
    if len(f) % 3:
        raise SyntaxError("fruit count is not a multiple of 3")
    prog = [(f[i] * 3 + f[i + 1], f[i + 2]) for i in range(0, len(f), 3)]
    jump, stack = {}, []
    for i, (verb, _) in enumerate(prog):
        if verb == 3:
            stack.append(i)
        elif verb == 5:
            if not stack:
                raise SyntaxError("unmatched close")
            j = stack.pop()
            jump[i], jump[j] = j, i
    if stack:
        raise SyntaxError("unmatched open")
    return prog, jump

def run(src, stdin=sys.stdin, stdout=sys.stdout):
    prog, jump = parse(src)
    basket = ([], [], [])
    def top(x):
        return basket[x][-1] if basket[x] else 0
    def put(x, v):
        if basket[x]:
            basket[x][-1] = v
        else:
            basket[x].append(v)
    def pop(x):
        return basket[x].pop() if basket[x] else 0
    pc = 0
    while pc < len(prog):
        verb, x = prog[pc]
        if verb == 0:
            put(x, top(x) + 1)
        elif verb == 1:
            put(x, top(x) - 1)
        elif verb == 2:
            v = top(x)
            ok = 0 <= v <= 0x10FFFF and not 0xD800 <= v <= 0xDFFF
            stdout.write(chr(v) if ok else "\uFFFD")
        elif verb == 3:
            if top(x) == 0:
                pc = jump[pc]
        elif verb == 4:
            c = stdin.read(1)
            put(x, ord(c) if c else 0)
        elif verb == 5:
            if top(x) != 0:
                pc = jump[pc]
        elif verb == 6:
            basket[(x + 1) % 3].append(pop(x))
        elif verb == 7:
            basket[(x - 1) % 3].append(pop(x))
        elif verb == 8:
            basket[(x + 1) % 3].append(top(x))
        pc += 1

if __name__ == "__main__":
    run(open(sys.argv[1], encoding="utf-8").read())

See also