esolang

Briefscript

Made to be as short as possible. Hello World is H, a factorial is iF and a truth machine is ios.

2015 · Turing complete: unknown · ●○○ easy · esolangs.org

Tested with 9 known programs · Test method

Run it

Expected: Hello, world!

The idea

Briefscript wins at code golf the way HQ9+ does. The common exercises are built in, one character each. The specification lists Hello World, the quine, factorial, roman numerals, a coin, a palindrome test, the 99 bottles of beer, Underload and the strange numbers. It says Briefscript always had shorter code than Microscript.

Read the story

Around the built ins sit two registers, CX and BX, input and output of numbers, a counted loop and two jumps. Those are enough for the cat, the sum of two inputs and the truth machine.

The machine

CommandDoes
H QPrint Hello, world! or Q
z OPrint 0 or 1
i IRead a number into CX, or two into CX and BX
oPrint CX
2 FSquare CX, or take its factorial, and print it
aAdd BX to CX and print it
RRead roman numerals and print their value
[ ]Skip past ] if CX is 0; take 1 from CX and go back while it is not 0
1Jump to the first character
sJump to the second character if the register is 1, else stop

The specification lists C twice, for the coin and for the palindrome test, gives no text for the bottles of 9 and does not say what U and S do, so this implementation leaves those four out. Its s tests an AX that nothing sets; this implementation tests CX, which the truth machine needs.

Example

iO[z] reads 3, prints a 1 and then a 0 for each count of the loop.
Expected: 1000
Expected: 0
Expected: 1994

iO[z] reads 3, prints a 1 and then a 0 for each count of the loop. The truth machine prints its input and stops on 0; on 1 it jumps back to o forever.

Patterns it teaches

  • Code golf: a built in for each exercise makes every program one or two characters.
  • Quine: Q prints Q.

Further

Stack-based

Write your own in Run Convert a program from Briefscript

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run briefscript -e 'H'
shib manual briefscript

Source

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

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

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