"Flip" Out with a Pathological Programming Language

As promised, this week, I've got a new friday pathological programming language. This one is another 2-dimensional language, but it's pretty different from any of the 2d languages I'm written about before. It's called "Flip", and the warped minds behind describe it as being sort of like "Programmers Billiards". It's a seriously neat language, but it is pretty large and complicated. So I'm not going to describe everything about it in detail: you'll have to read the language manual for that. But I'll describe enough to give you the flavor of it, and show you a couple of examples to whet your appetite.

As usual for 2D programming languages, the program consists of a 2-dimensional playfield, where the program is described by the layout of characters on the field. In Flip, the playfield contains two kinds of things: stationary objects (that is, objects that don't move on their own), and balls, which are objects that go bouncing around the playfield. Balls carry number-values, and the value inside a ball can have an effect on how interacts when it hits other things.

The simplest stationary objects are walls. Horizontal walls are written as "-" signs, and vertical walls are written as "|" (pipe) characters. Horizontal and vertical walls are called mirrors. "/" and "\" are diagonal walls - also called flippers, for reasons that you'll see later. Balls bounce off of mirrors by reversing direction; they bounce off of flippers by making 90 degree turns.

A more interesting stationary object is the sluice. A sluice is an object
that only lets things pass through it in one direction. "^", ">", "v", and "<" are the four sluices - they each let balls go through them if they're moving in the direction
that the sluice points. If balls hits a sluice coming from the direction that it's pointing, then it reverses direction; if it hits it from the side, it bounces and starts moving in the direction that the sluice is pointing.

Here's where it starts to get interesting. If there's a digit in the program, and a ball hits it, the ball will bounce back as if it hit a mirror, and a new ball will be created carrying the digit as its value. So, for example, here's a little program. The "=" signs are just there to help mark columns - only the "2" is really part of the program:

    2
============

A initial ball enters the program at the top left moving right. It moves until it hits to 2, then it will bounce back, moving left until it exits off the right edge; and a new ball carrying 2 will start moving to the right.

Here's another. Again, the "="s don't really do anything except set the width of the playfield:

    2    4    
==============

A ball will enter from the left, hit the 2, and bounce back and move off the field. When it hits the 2, a new ball carrying 2 will start moving to the right. It will get to the 4, hit it, and bounce back, moving to the left, and a 4-ball will be created moving to the right. The 2-ball will move left at the same time the 4-ball moves right; the four will end up falling off the right edge at the same time that the 2-ball hits the 2. Then a new
2-ball will be created, moving left, and the old 2-ball will bounce and start moving right. And so on - the 2-ball will keep bouncing back and force, creating 2s and 4s.

To do computation, there are things called tarpits. "+" and "*" are the two tarpits: "+" for addition, and "*" for multiplication. The first ball that hits a tarpit gets stuck. The second one that hits it gets added or multiplied by the stuck ball, and keeps going the same direction, and the tarpit is then empty again, so the next ball that hits it gets stuck. So, for example:

  > 2 + *  
===========

First, an initial ball comes in, goes through the sluice, and hits the 2, creating a 2-ball. The 2-ball goes to the "+" and gets stuck. The initial ball bounces off the sluice, back to the 2, which creates another two, which hits the +, and then gets turned into a four, because the 2 stuck in the "+" tarpit gets added to it. The initial ball keeps bouncing, creating 2-balls, which get to the "+", so every other bounce of the initial ball, you'll get a 4-ball coming out of the tarpit. It gets stuck in the "*"; every other time a "4" gets created and hits the "*" tarpit, it turns into a 16. So that produces a series of 16s falling off the right-hand edge.

For input and output: if a ball hits a "p", it outputs its value as a number; if it hits a "P", it outputs its value as a character. So:

  >  2  +  *  p
=================

is a program which repeatedly prints out the number sixteen.

"X" is where it really starts getting interesting. "X" is called a processor. By default, when a ball hits a processor, the processor eats the ball, and creates two copies of it, sending them off at right-angles to the direction from which the processor was hit.

But that's just the default. Most of the stationary objects in Flip can have modifiers, and processors get the best set of modifiers.

Let's look at the simplest modifier: "@", which means "always". We can attach an "@" to a flipper, by putting it on one of the flippers corners. Then when the flipper gets hit by a ball, it will bounce the ball as normal, and it will rotate 90 degrees. "+" means "positive", so if the modifier of a flipper is "+", then it will only rotate if the ball that hits it has a positive value. There are a lot of modifiers: check the manual for the list.

Some examples of programs, to get you interested enough to go look. Here's "hello world" - download the interpreter, and prepare to be mesmerized watching it run to see how this prints hello world:

  \   Dette program skriver "Hello World!\n" ud.

  1  /2 \  /2 \  /2 \  /2 \  /2 \  /2 \  /0 \
      @     @     @     @     @     @     @  
     ^  *\ ^  *\ ^  *\ ^  *\ ^  *\ ^  *\ ^  >*\
  \  X   \ X   \ X   \ X   \ X   \ X   \ X      
 v                       +                 + 0/
    //    //    //    /X /  //    //    /X / @   
 v+           +                 +     +      0/
  \ X\    \\  \ X\    \\    \\  \ X\  \ X\   @    
 v                 +     +           +     + 0/
    //    //    /X /  /X /  //    /X /  /X / @     
 v            +     +           +     +      0/
    \\    \\  \ X\  \ X\    \\  \ X\  \ X\   @   
 v     +     +     +     +           +     + 0/
    /X /  /X /  /X /  /X /  //    /X /  /X / @  
 v                              +            0/
    \\    \\    \\    \\    \\  \ X\    \\   @  
 v     +     +     +           +           + 0/
    /X /  /X /  /X /  //    /X /  //    /X / @    
 v+     +     +     +           +     +      0/
  \ X\  \ X\  \ X\  \ X\    \\  \ X\  \ X\   @   
 v           +                 +     +     + 0/
    //    /X /  //    //    /X /  /X /  /X / @   
 v            +     +           +     +      0/
    \\    \\  \ X\  \ X\    \\  \ X\  \ X\   @   
 v                 +                 +     + 0/
    //    //    /X /  //    //    /X /  /X / @   
 v+                             +            0/
  \ X\    \\    \\    \\    \\  \ X\    \\   @   
 v           +           +                   0/  
 P  //    /X /  //    /X /  //    //    //   @  
 Q                                           0/  
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  (C) Copyright 2001 Rune Zedeler & Erik Søe Sørensen

One more example, which is absolutely brilliant in its simple
elegance: the Fibonacci series generator:

  \   / \ p
  v   >   X
  1@      
  \   > X   
      \ + /
      Q-
==============
  Fibonacci.

Now, go download it, and play. You know you want to!

More like this

Whoah... this is like thise games where you pour the little balls in at the top and watch them bounce around as they go down. Or an oddball Pinball game.

Ooh, mesmerizing AND it can do useful algorithms! Two in one!

I've come across Flip repeatedly, but always sort of dismissed it up until this point. You're like an ambassador of esolangs!

I'd like to take this time to declare Flip as being part of an entirely new programming paradigm (inspired by thge words of Markk) - Pachinko Programming.

By Brian Thompson (not verified) on 20 Apr 2007 #permalink

A initial ball enters the program at the top left moving right. It moves until it hits to 2, then it will bounce back, moving left until it exits off the right edge; and a new ball carrying 2 will start moving to the right.

???

RGOP: Rube Goldberg Oriented Programming

RGOP: Rube Goldberg Oriented Programming

I presume Mark will get around to covering some of Chris Pressey's Rube languages soon...

By Ãrjan Johansen (not verified) on 20 Apr 2007 #permalink

This language reminds me of a lot of my least favorite aspects of Max.

fascinating stuff Mark. a great find, and nicely described.

now how do rewrite my erp system in flip?

Yeah, but how well does it perform (kidding)? How do you even do an algorithmic analysis of a language like this? Haha.

Your original link to a list of "esoteric" languages was a dead, but this list is pretty good. There are lots of languages by Chris Pressey, of course.

a language created for programming a quantum computer. "balls" are possible locations of photons. when they get "split" they are actually just 2 uncertainty values. kidding. but it does remind me of something created to do that sort of computation. a metaphor for some substrate that actually functions in a similar way, and allows for massively parallel computing.

So that's what you get when you cross a Turing machine and a pinball machine. Seems like it'd be more fun to watch in action than glider guns forming a logic gate.