Sharp
Written #. A stack language whose numbers are written as hex strings.
Nick-1666, 2022 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Nick-1666 made #, said "sharp", in 2022, after brainfuck and ><>. A number in the program can only be written as a hex string. (48) pushes 72, with place value respected, and the empty string () pops, so popping needs no command of its own. Loops are brainfuck's brackets, tested on the stack. The official interpreter is written in C.
The machine
| Command | Does |
|---|---|
(hex) | Push a number written with 0 to 9 and A to F |
() | Pop |
$ = | | Swap, duplicate, reverse the stack |
+ - * / % | Pop two, push the result |
^ | Push the size of the stack |
. : | Read a character as a digit, or as its code |
, ; | Pop and print as a number, or as a character |
[ | Pop, and skip past ] if it was 0 |
] | Jump back to [ if the top is not 0 |
# | Comment to the end of the line |
[ pops what it tests and ] only looks, so a loop leaves a copy on the stack for the next test. That is why both programs in the specification duplicate with = before they test. The specification leaves open what an empty stack holds. It reads as 0, which lets the Hello World stop after its last character. Numbers are 32 bits wide, like a C int.
Example
The truth machine reads a digit and copies it.
The truth machine reads a digit and copies it. On 0 the loop is skipped and the copy is printed. On 1 the loop pushes two 1s each time, prints one and tests the other, so it never ends.
The Hello World pushes its letters, reverses the stack so that H is on top, and prints until the stack is empty. The specification says it pushes Hello World!, but it has (6C) only once.
Further
Ideas it shows
See also
Stack-based
Write your own in Run Convert a program from Sharp
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: sharp.
Command line
shib run sharp -e '# Truth machine program by Nick-1666 29/05/2022
.=[(1)=,],' --input '0'shib manual sharpSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/sharp.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org