Emoji
A stack language where every command is an emoji: π¬ quotes a string and β‘ prints it.
2015 Β· Turing complete: unknown Β· βββ moderate Β· esolangs.org
Tested with 6 known programs Β· Hello World on Try It Online: identical except the line end Β· Test method
Run it
The idea
Emoji dates from 2015. Its commands are single emoji, and almost everything else in a program is ignored. The values on the stack are Python's own, because the interpreter TIO runs, emoji.py, is a small Python program that hands the work to Python: strings, whole numbers, floats, booleans and lists.
Read the story
Code is data. β½ β¦ π pushes a piece of program as a string, π runs it, and π is a while loop built from two such strings, a condition and a body.
The machine
| Code | Does |
|---|---|
π¬textπ¬ | Push a string |
β½codeπ | Push code as a string; they nest |
β‘ | Print, with a newline |
π’ π₯ πΏ π€ | String to float, int(), round, round up |
π« π πͺ π΄ πΈ | Add, subtract, multiply, divide, modulo |
π¬ π£ π | Equal, less, greater |
π² π³ π΄ | True, false, not |
π β¦ π§ | If: skip to the matching π§ when false |
π β¦ π§ | Else |
π | Loop: pop a body and a condition, run while the condition is true |
π | Run a string as code |
π₯ π | Duplicate, swap |
π£ π π | Character to code, code to character, number to hex |
π² π± | Store a value under a name, read it back |
π β π | Length, substring, index |
π π | New list, append |
π π | Upper case, lower case |
π« joins as text when either side is a string, and π΄ always gives a float. Numbers typed as strings need π’, which gives a float; π₯ turns that into a whole number.
This implementation follows emoji.py at github.com/vpzomtrrfrt/emoji.py. TIO passes arguments that start on the stack as strings; in this implementation each line of input is one. Python's % formatting of strings is left out, and an error ends the run without the state dump the reference prints.
Example
The second multiplies two floats, so Python prints 42.0.
The second multiplies two floats, so Python prints 42.0. The third is a countdown: the condition prints the number, takes one off and leaves a copy to test; the body is empty.
Patterns it teaches
- Stack machines: every emoji takes its arguments from the stack.
- Code as data: loops and functions are strings run on demand.
Further
- esolangs.org/wiki/Emoji
- emoji.py, the Python interpreter TIO runs
See also
Also in Camouflage
Write your own in Run Convert a program from Emoji
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: emoji.
Command line
shib run emoji -e 'π’π¬1π¬π’π«β‘' --input '41
'shib manual emojiSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/emoji.js
Docs: Kernel instructions Β· The .shib format Β· Command line Β· Adding a language
Source esolangs.org (CC0) Β· Edit on esolangs.org