{"id":392,"date":"2007-04-20T08:00:00","date_gmt":"2007-04-20T08:00:00","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2007\/04\/20\/flip-out-with-a-pathological-programming-language\/"},"modified":"2007-04-20T08:00:00","modified_gmt":"2007-04-20T08:00:00","slug":"flip-out-with-a-pathological-programming-language","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2007\/04\/20\/flip-out-with-a-pathological-programming-language\/","title":{"rendered":"&quot;Flip&quot; Out with a Pathological Programming Language"},"content":{"rendered":"<p> As promised, this week, I&#8217;ve got a new friday pathological programming language. This one is another 2-dimensional language, but it&#8217;s pretty different from any of the 2d languages I&#8217;m written about before. It&#8217;s called &#8220;<a href=\"http:\/\/www.daimi.au.dk\/~eriksoe\/Flip\">Flip<\/a>&#8220;, and the warped minds behind describe it as being sort of like &#8220;Programmers Billiards&#8221;. It&#8217;s a seriously neat language, but it is pretty large and complicated. So I&#8217;m not going to describe everything about it in detail: you&#8217;ll have to read the <a href=\"http:\/\/www.daimi.au.dk\/~eriksoe\/Flip\/language.html\">language manual<\/a> for that. But I&#8217;ll describe enough to give  you the flavor of it, and show you a couple of examples to whet your appetite.<\/p>\n<p><!--more--><\/p>\n<p> As usual for 2D programming languages, the program consists of a 2-dimensional <em>playfield<\/em>, 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&#8217;t move on their own), and <em>balls<\/em>, 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.<\/p>\n<p> The simplest stationary objects are <em>walls<\/em>. Horizontal walls are written as &#8220;-&#8221; signs, and vertical walls are written as &#8220;|&#8221; (pipe) characters. Horizontal and vertical walls are called <em>mirrors<\/em>. &#8220;\/&#8221; and &#8220;&#8221; are diagonal walls &#8211; also called <em>flippers<\/em>, for reasons that you&#8217;ll see later. Balls bounce off of mirrors by reversing direction; they bounce off of flippers by making 90 degree turns.<\/p>\n<p> A more interesting stationary object is the <em>sluice<\/em>. A sluice is an object<br \/>\nthat only lets things pass through it in one direction. &#8220;^&#8221;, &#8220;&gt;&#8221;, &#8220;v&#8221;, and &#8220;&lt;&#8221; are the four sluices &#8211; they each let balls go through them if they&#8217;re moving in the direction<br \/>\nthat the sluice points. If balls hits a sluice <em>coming from<\/em> the direction that it&#8217;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.<\/p>\n<p> Here&#8217;s where it starts to get interesting. If there&#8217;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&#8217;s a little program. The &#8220;=&#8221; signs are just there to help mark columns &#8211; only the &#8220;2&#8221; is really part of the program:<\/p>\n<pre>\n2\n============\n<\/pre>\n<p> 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.<\/p>\n<p> Here&#8217;s another. Again, the &#8220;=&#8221;s don&#8217;t really do anything except set the width of the playfield:<\/p>\n<pre>\n2    4\n==============\n<\/pre>\n<p> 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<br \/>\n2-ball will be created, moving left, and the old 2-ball will bounce and start moving right. And so on &#8211; the 2-ball will keep bouncing back and force, creating 2s and 4s.<\/p>\n<p> To do computation, there are things called <em>tarpits<\/em>. &#8220;+&#8221; and &#8220;*&#8221; are the two tarpits: &#8220;+&#8221; for addition, and &#8220;*&#8221; 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:<\/p>\n<pre>\n&gt; 2 + *\n===========\n<\/pre>\n<p> First, an initial ball comes in, goes through the sluice, and hits the 2, creating a 2-ball. The 2-ball goes to the &#8220;+&#8221; 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 &#8220;+&#8221; tarpit gets added to it. The initial ball keeps bouncing, creating 2-balls, which get to the &#8220;+&#8221;, so every other bounce of the initial ball, you&#8217;ll get a 4-ball coming out of the tarpit. It gets stuck in the &#8220;*&#8221;; every other time a &#8220;4&#8221; gets created and hits the &#8220;*&#8221; tarpit, it turns into a 16. So that produces a series of 16s falling off the right-hand edge.<\/p>\n<p> For input and output: if a ball hits a &#8220;p&#8221;, it outputs its value as a number; if it hits a &#8220;P&#8221;, it outputs its value as a character. So:<\/p>\n<pre>\n&gt;  2  +  *  p\n=================\n<\/pre>\n<p> is a program which repeatedly prints out the number sixteen.<\/p>\n<p> &#8220;X&#8221; is where it really starts getting interesting. &#8220;X&#8221; is called a <em>processor<\/em>. 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.<\/p>\n<p> But that&#8217;s just the default. Most of the stationary objects in Flip can have <em>modifiers<\/em>, and processors get the best set of modifiers.<\/p>\n<p> Let&#8217;s look at the simplest modifier: &#8220;@&#8221;, which means &#8220;always&#8221;. We can attach an &#8220;@&#8221; 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, <em>and<\/em> it will rotate 90 degrees. &#8220;+&#8221; means &#8220;positive&#8221;, so if the modifier of a flipper is &#8220;+&#8221;, 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.<\/p>\n<p> Some examples of programs, to get you interested enough to go look. Here&#8217;s &#8220;hello world&#8221; &#8211; download the interpreter, and prepare to be mesmerized watching it run to see how this prints hello world:<\/p>\n<pre>\n   Dette program skriver \"Hello World!n\" ud.\n1  \/2   \/2   \/2   \/2   \/2   \/2   \/0 \n@     @     @     @     @     @     @\n^  * ^  * ^  * ^  * ^  * ^  * ^  &gt;*\n  X    X    X    X    X    X    X\nv                       +                 + 0\/\n\/\/    \/\/    \/\/    \/X \/  \/\/    \/\/    \/X \/ @\nv+           +                 +     +      0\/\n X    \\   X    \\    \\   X   X   @\nv                 +     +           +     + 0\/\n\/\/    \/\/    \/X \/  \/X \/  \/\/    \/X \/  \/X \/ @\nv            +     +           +     +      0\/\n\\    \\   X   X    \\   X   X   @\nv     +     +     +     +           +     + 0\/\n\/X \/  \/X \/  \/X \/  \/X \/  \/\/    \/X \/  \/X \/ @\nv                              +            0\/\n\\    \\    \\    \\    \\   X    \\   @\nv     +     +     +           +           + 0\/\n\/X \/  \/X \/  \/X \/  \/\/    \/X \/  \/\/    \/X \/ @\nv+     +     +     +           +     +      0\/\n X   X   X   X    \\   X   X   @\nv           +                 +     +     + 0\/\n\/\/    \/X \/  \/\/    \/\/    \/X \/  \/X \/  \/X \/ @\nv            +     +           +     +      0\/\n\\    \\   X   X    \\   X   X   @\nv                 +                 +     + 0\/\n\/\/    \/\/    \/X \/  \/\/    \/\/    \/X \/  \/X \/ @\nv+                             +            0\/\n X    \\    \\    \\    \\   X    \\   @\nv           +           +                   0\/\nP  \/\/    \/X \/  \/\/    \/X \/  \/\/    \/\/    \/\/   @\nQ                                           0\/\n&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\n(C) Copyright 2001 Rune Zedeler &amp; Erik S\u00f8e S\u00f8rensen\n<\/pre>\n<p> One more example, which is absolutely <em>brilliant<\/em> in its simple<br \/>\nelegance: the Fibonacci series generator:<\/p>\n<pre>\n   \/  p\nv   &gt;   X\n1@\n   &gt; X\n + \/\nQ-\n==============\nFibonacci.\n<\/pre>\n<p> Now, go download it, and play. You know you want to!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As promised, this week, I&#8217;ve got a new friday pathological programming language. This one is another 2-dimensional language, but it&#8217;s pretty different from any of the 2d languages I&#8217;m written about before. It&#8217;s called &#8220;Flip&#8220;, and the warped minds behind describe it as being sort of like &#8220;Programmers Billiards&#8221;. It&#8217;s a seriously neat language, but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[92],"tags":[],"class_list":["post-392","post","type-post","status-publish","format-standard","hentry","category-pathological-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-6k","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}