esolang

Befalse

FALSE's stack, Befunge's grid and SNUSP's mirrors and calls, glued together without a single letter.

Ian Osgood, 2005 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: 1234

The idea

Ian Osgood made Befalse in 2005 from three parents. From FALSE it takes the stack and the arithmetic. From Befunge it takes a grid of code that the program can read and overwrite. From SNUSP it takes the way the instruction pointer moves: it only turns at mirrors / and \, and it can call and return like a subroutine.

Read the story

Like SNUSP, no letters are used. The specification jokes that "no letters were harmed". Every command is a symbol, and the code looks like a small drawing of its own control flow.

The call stack is the interesting part. : remembers where the pointer is and which way it goes. ; goes back there. Because a call is only "remember this spot", recursion is a loop drawn on the grid that passes through a :.

The machine

A grid of characters, a pointer that starts at the top left going right, a data stack and a call stack. The program stops when the pointer leaves the grid or ; finds the call stack empty.

CharDoes
/ \Mirrors: turn the pointer
!Skip the next cell
?Pop; skip the next cell if it was 0
: ;Call (remember position and direction) / return there and skip one cell
{ }Move a value to / from the call stack
0…9 (123Push a digit; ( and digits push a whole number
$ # % ^Dup, drop, swap, over
+ - * _ & \| ~ >Math and logic as in FALSE
` | Divmod: remainder, then quotient
@ =Read / write a cell of the code
"…" . 'Push characters, print a character, read a number

The specification lists the operators but not every detail. This implementation takes the coordinates of @ and = in Befunge's order, and popping an empty stack gives 0.

Example

The top row pushes 1234 and divides by 10, leaving 4 and 123.

The top row pushes 1234 and divides by 10, leaving 4 and 123. If the quotient is not 0, the mirrors send the pointer through : and back to the start of the division: a recursive call. When the quotient is 0, the bottom row adds 48 to the remainder, prints it, and ; returns to the level above, which prints its own digit. So the digits come out in the right order.

Patterns it teaches

Try this

  1. Change the example so it prints a different number.
  2. Print Hi with " and two ., then make the pointer leave the grid.
  3. Hard: print the number with a minus sign when it is negative.

Further

Self-modifying

Two-dimensional languages

Write your own in Run Convert a program from Befalse

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run befalse -e '(1234!/55+`$?\\
      \   /!://
    ;.+*68/!#/'
shib manual befalse

Source

Module
langs/stack/ports.js
Interpreter
langs/stack/befalse.js

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

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