{"id":359,"date":"2007-03-23T13:00:08","date_gmt":"2007-03-23T13:00:08","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2007\/03\/23\/programming-with-shapes-clunk\/"},"modified":"2007-03-23T13:00:08","modified_gmt":"2007-03-23T13:00:08","slug":"programming-with-shapes-clunk","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2007\/03\/23\/programming-with-shapes-clunk\/","title":{"rendered":"Programming with Shapes: Clunk"},"content":{"rendered":"<p> Today&#8217;s bit of pathology is a really silly, and really fun language called <a href=\"http:\/\/esoteric.sange.fi\/essie2\/download\/clunk\/\"><em>Clunk<\/em><\/a>, with a downloadable package containing a perl implementation <a href=\"http:\/\/esoteric.sange.fi\/essie2\/download\/clunk.zip\">here<\/a>. I&#8217;m<br \/>\nnot sure that it&#8217;s Turing compete, but my best guess is that it is. It&#8217;s another two dimensional<br \/>\nlanguage, but it&#8217;s very different from any of the other 2d languages that we&#8217;ve look at, because it<br \/>\ndoesn&#8217;t rely on an instruction pointer moving around the playfield; instead, it computes by<br \/>\ncreating an image by fitting together pieces according to some pre-determined rules.<\/p>\n<p><!--more--><\/p>\n<p> A Clunk program consists of a file containing a set of <em>shapes<\/em>. A shape is a fully<br \/>\nconnected two-dimensional figure of non-space characters. The shape can be made up of any visible characters you want &#8211; but digits and &#8220;@&#8221; characters have some special meanings. The sum of all<br \/>\nof the digits in a shape are called the shape&#8217;s &#8220;connectitude&#8221;. If the shape contains no<br \/>\ndigits, then it&#8217;s connectitude is 1. If a shape contains a zero, but no other digits,then its<br \/>\nconnectitude is 0.<\/p>\n<p> The way that a Clunk program works is that each step, it tries to place one figure onto the<br \/>\nfield. In the first step, if any shape(s) in the program contain an &#8220;@&#8221; character,<br \/>\nthen one of them is randomly selected and put onto the playfield. After that, shapes are<br \/>\nplaced, one per step, until no more can be placed. Placement is done according to the following rules:<\/p>\n<ol>\n<li> A shape must be placed so that any places where one of it&#8217;s edges touch another shape&#8217;s<br \/>\nedge, the characters on the touching edges match.<\/li>\n<li> A shape must be placed so that the number of places where it&#8217;s edges<br \/>\ntouch other shapes is <em>at least<\/em> it&#8217;s connectitude. (Note that this means that<br \/>\na shape with connectitude 0 can be always be placed, by putting them somewhere where<br \/>\nthere are no other shapes &#8211; so including a connectitude 0 shape means your program will never terminate.)<\/li>\n<\/ol>\n<p> Clunk has no input or output. But effectively, it uses the final image on the playfield for out. Let&#8217;s look at an example to make it clearer. Here&#8217;s &#8220;Hello World&#8221; in Clunk:<\/p>\n<pre>\n@a-b-c-d-e-f-g-h-i-j-k-l-m#\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\nH    O   R\na    e   j  ,\nL   O    f\nE  d   i\nb       L\nW   k\nL   h      .\nc        D m\nl\n<\/pre>\n<p> The program first places the shape with the &#8220;@&#8221; onto the field:<\/p>\n<pre>\n@a-b-c-d-e-f-g-h-i-j-k-l-m#\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n<\/pre>\n<p> Then it tries to find other things to place. Each of the other shapes has one of the letters of &#8220;Hello world&#8221;, and one of the letters from the initial shape. Each shape has connectitude one, and each one can only possibly fit in one place. So all of the pieces get places. and we end up with:<\/p>\n<pre>\nH E L L O ,   W O R L D .\na b c d e f   h i j k l m\n@a-b-c-d-e-f-g-h-i-j-k-l-m#\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n<\/pre>\n<p> Here&#8217;s a nifty but silly program &#8211; it draws an infinite maze-like figure.<\/p>\n<pre>\nc    d\nc\/-- -d\n|    |\n|    |\n|    |\nf-- -\/e\nf    e\n<\/pre>\n<p> This is the one that I think is incredibly cool. I&#8217;m not going to explain it &#8211; because if you download the interpeter and run it, watching it run shows you exactly how it works, far more clearly than I can do it. This is a binary adder written entire in strange shapes.<\/p>\n<pre>\n@O\n@|\n@|I   |O   |I   |O   |b\n@|    |    |    |    |b\n@|.O  |.I  |.I  |.O  |b\n@|    |    |    |    |b\n@aaaaaaaaaaaaaaaaaaaaaa\nO      I\n_      _\nO.3.O  I.3.O\n.      .\nO.     O.\n.      .\nO      O\nI      O\n_      _\nO.3.O  I.3.I\n.      .\nO.     O.\n.      .\nI      I\nI      O\n_      _\nO.3.O  I.3.I\n.      .\nI.     I.\n.      .\nO      O\nO      I\n_      _\nO.3.I  I.3.I\n.      .\nI.     I.\n.      .\nI      I\n<\/pre>\n<p> Here&#8217;s the result when it&#8217;s done. Note that it&#8217;s going backwards &#8211; the least significant bit is to the left:<\/p>\n<pre>\nI    I    O    I\n_    _    _    _\n@OO.3.OO.3.OO.3.II.3.O\n@|  .    .    .    .\n@|II. |OO. |II. |OO. |b\n@|  . |  . |  . |  . |b\n@|.OO |.II |.II |.OO |b\n@|    |    |    |    |b\n@aaaaaaaaaaaaaaaaaaaaaa\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s bit of pathology is a really silly, and really fun language called Clunk, with a downloadable package containing a perl implementation here. I&#8217;m not sure that it&#8217;s Turing compete, but my best guess is that it is. It&#8217;s another two dimensional language, but it&#8217;s very different from any of the other 2d languages that [&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-359","post","type-post","status-publish","format-standard","hentry","category-pathological-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-5N","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/359","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=359"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/359\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=359"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}