esolang

Cheers

Beverage-oriented programming. Data goes into a glass, the loop runs until you are drunk, and the output comes back up.

2017 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Hi

The idea

Cheers is from 2017 and takes after INTERCAL and Chef. A program prepares drinks, pours them into a working glass that holds 500 ml, and drinks it. Every drink raises an intoxication counter by its strength times its volume, so 40 ml of 40% vodka adds 16. The only loop, binge, runs while the counter is below 200.

Read the story

Output is throw up. It brings up every drink, the last one first, as a character. The volume is the character code and the strength is how many times it appears, so 100 ml of a 5% drink comes up as ddddd.

The machine

StatementDoes
prepare drink wine 12%Make a drink; prepare soft drink cola makes one of 0%
prepare lemon syrupMake a syrup, which has names of its own
prepare drink U-Boot as ... endMake a drink from what its statements pour
pour fast 200 ml of wineMix into the glass, averaging the strength
pour slowly 200 ml of wineAdd a layer on top; a plain pour is fast for drinks and slow for syrups
spill 50 ml sip 50 mlPour away or drink, from the top layer down
cheersDrink the whole glass, top layer first
ask for a drinkRead a run of n equal characters c and pour c ml of n%
throw upPrint every drink drunk, last first, and set the counter to 0
binge ... endRepeat while the counter is below 200
mumbleMake the rest of the statement a comment

Statements end at , . ; ? ! or a line break, and case does not matter. What runs over the brim of the glass is spilled from the top. The specification does not say what ask for a drink does when the input runs out. Its echo and reverse only stop if the binge ends there, so this implementation leaves the binge at once.

Example

A shot of 1% per letter, drunk in reverse order, because what goes down last comes up first.

A shot of 1% per letter, drunk in reverse order, because what goes down last comes up first.

The echo throws up each drink right away. Its reverse keeps drinking and throws up once, at the end.

Expected: hello
Expected: olleh

The Hello world prepares ten drinks, nine of 1% and one of 2%. That one is the Double-Lorraine, 108 ml of which comes up as ll.

Patterns it teaches

  • Camouflage: a program that reads as a night at the bar.

Further

Stack-based

Write your own in Run Convert a program from Cheers

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: cheers.

Command line

shib run cheers -e 'binge
    ask for a drink
    cheers
    throw up
end' --input 'hello'
shib manual cheers

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/cheers.js

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

Source esolangs.org (CC0) · Edit on esolangs.org