esolang

SNUSP

Brainfuck drawn as a railway map. Loops are real loops of track, and the train stops when it runs off the edge.

Daniel Brockman, 2003 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 4 examples and 5 known programs · Hello World on Try It Online: identical · Test method

Run it

Example

Expected output

ab

Output


The idea

Daniel Brockman made SNUSP in 2003. (The name is a recursive joke, "SNUSP's Not Unix, but a Structured Path", and a nod to its predecessor, the language PATH.) It keeps Brainfuck's tape and its six data commands, but throws away [ and ]. Instead the code is a 2D picture, and control flow is done with two mirrors and two skip commands.

Read the story

The fun is that a SNUSP loop looks like a loop. You draw a rectangle of track, put a test where the train can leave it, and the picture is the program.

It comes in three sizes:

  • Core SNUSP: the Brainfuck commands, the mirrors, ! and ?.
  • Modular SNUSP: adds @ and #, a call stack, so you can write subroutines.
  • Bloated SNUSP: adds a 2D memory, random numbers and threads.

The machine

A grid of characters, a tape of cells, and an IP that starts on $ (or the top-left if there is none) moving right. The grid does not wrap: running off any edge ends the program.

CharDoes
> < + - . ,As in Brainfuck: move, change, print, read
/Mirror: right becomes up, up becomes right, left becomes down, down becomes left
\Mirror: right becomes down, down becomes right, left becomes up, up becomes left
!Skip the next cell
?Skip the next cell if the current cell is 0
@(Modular) push the current position and direction onto the call stack
#(Modular) pop it, and continue one cell past the @; with an empty stack, stop
: ; & %(Bloated) memory up and down, split into two threads, random number

Every other character does nothing. By convention = and | are used to draw horizontal and vertical track, so the eye can follow it.

Example

Print A: set cell 0 to 8, then loop eight times adding 8 to cell 1.

Print A: set cell 0 to 8, then loop eight times adding 8 to cell 1. That gives 64; add one more and print.

$++++++++!/?\>+.
          | \>++++++++<-\
          \=============/

Follow the train. It sets cell 0 to 8, then ! jumps over the /. At ? the cell is not 0, so it hits \ and turns down, then right along row 1: >++++++++<-. At the end it turns down, runs back left along row 2, turns up at the left \ and right again at /, arriving at ? from the left. After eight laps cell 0 is 0, ? skips the \, and the train runs on: >+. prints 65, A. Then it leaves the grid.

It is saved as langs/museum/examples/a.snusp:

This implementation does Core and Modular SNUSP, not Bloated.

Checked examples

Example

Expected output

(nothing)

Output


Example

Expected output

12

Output


Example

Expected output

81

Output


Quirks

  • A run stops after 3,000,000 steps.

Try this

  1. Change the example to print B, then AB.
  2. Write cat that stops when , reads 0.
  3. Hard: write a modular SNUSP program with one subroutine that prints the current cell twice, and call it twice.

Patterns it teaches

  • Two-dimensional control flow: with only two mirrors and a conditional skip, every structured loop becomes a drawn circuit.
  • Turing tarpit: Core SNUSP is Brainfuck in another shape, so it is just as universal and just as painful.
  • Nondeterminism: Bloated SNUSP's & splits the IP into threads that run side by side, and % rolls a random number.

Further

Two-dimensional languages

Cell-based

Write your own in Run Convert a program from SNUSP

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run snusp -e '/!$\
\>./'
shib manual snusp

Source

Module
langs/grid/index.js
Interpreter
langs/grid/snusp.js

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

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