{"id":73,"date":"2006-07-14T08:45:00","date_gmt":"2006-07-14T08:45:00","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2006\/07\/14\/gmbm-friday-pathological-programming-languages\/"},"modified":"2006-07-14T08:45:00","modified_gmt":"2006-07-14T08:45:00","slug":"gmbm-friday-pathological-programming-languages","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2006\/07\/14\/gmbm-friday-pathological-programming-languages\/","title":{"rendered":"GM\/BM Friday: Pathological Programming Languages"},"content":{"rendered":"<p>In real life, I&#8217;m not a mathematician; I&#8217;m a computer scientist. Still a math geek, mind you, but what I really do is very much in the realm of applied math, researching how to build systems to help people program.<br \/>\nOne of my pathological obsessions is programming languages. Since I first got exposed to TRS-80 Model 1 BASIC back in middle school, I&#8217;ve been absolutely nuts programming languages. Last time I counted, I&#8217;d learned about 130 different languages; and I&#8217;ve picked up more since then. I&#8217;ve written programs most of them. Like I said, I&#8217;m nuts.<br \/>\nAnyway, I decided that it would be amusing to inflict my obsession on you, my readers, with a new feature: the friday pathological programming language. You see, there are plenty of *crazy* people out there; and many of them like to invent programming languages. Some very small number of them try to design good languages and succeed; a much larger number try to design good languages and fail; and *then* there are the folks who design the languages I&#8217;m going to talk about. They&#8217;re the ones who set out to design *bizzare* programming languages, and succeed brilliantly. They call them &#8220;esoteric&#8221; programming languages. I call them evil.<br \/>\nToday, the beautiful grand-daddy of the esoteric language family: the one, the only, the truly and deservedly infamous: [Brainfuck!][bf], designed by Urban M\u00fcller. (There are a number of different implementations available; just follow the link.)<br \/>\nOnly 8 commands &#8211; including input and output &#8211; all written using symbols. And yet Turing complete; and not just Turing complete, but actually based on a *real* [formal theoretical design][pprimeprime]. And it&#8217;s even been implemented [*in hardware*!][bf-hard]<br \/>\nBrainFuck is based on something very much like a twisted cross between a [Turing machine][turing] and a [Minsky machine][minsky]. It&#8217;s got the idea of an input tape, like the turing machine. But unlike the turing machine, each cell of the tape stores a number, which can be incremented or decremented, like a Minsky machine. And like a Minsky, the only control flow is a test for zero.<br \/>\nThe 8 instructions:<br \/>\n1. **&gt;**: move the tape head one cell forward.<br \/>\n2. **+++++++++.++++++-.+++++++..+++.&gt;++++&lt;&gt;.&lt;&#8212;&#8212;.++++++<br \/>\n.+++.&#8212;&#8212;.&#8212;&#8212;&#8211;.&gt;+.<br \/>\nLet&#8217;s pull that apart just a bit so that we can hope to understand.<br \/>\n* &#8220;++++++++&#8221;: store the number &#8220;8&#8221; in the current tape cell. We&#8217;re going to use that as a loop index, so the loop is going to repeat 8 times.<br \/>\n* &#8220;[&gt;+++++++++.&#8221;: go to the cell after the loop index, and output what&#8217;s there. That outputs the &#8220;72&#8221; as a character: &#8220;H&#8221;.<br \/>\n* &#8220;++++++-.&#8221;: Advance past the index, subtract one, and output. That&#8217;s 101, or &#8220;e&#8221;.<br \/>\nContinues in pretty much the same vein, using a couple of tape cells, and running loops to generate the values of the characters. Beautiful, eh?<br \/>\nIf that didn&#8217;t seem impressive enough, [here][bf-fib] is a really gorgeous implementation of a fibonacci sequence generator, with documentation. The BF compiler used to write this ignores any character other than the 8 commands, so the comments don&#8217;t need to be marked in any way; they just need to be really careful not to use punctuation.<\/p>\n<pre>\n+++++++++++ number of digits to output\n&gt; #1\n+ initial number\n&gt;&gt;&gt;&gt; #5\n++++++++++++++++++++++++++++++++++++++++++++ (comma)\n&gt; #6\n++++++++++++++++++++++++++++++++ (space)\n&lt;&lt;&lt;&lt;&lt; #1\ncopy #1 to #7\n[&gt;&gt;&gt;&gt;&gt;&gt;+&gt;+&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;[&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;-]\n\n++++++++++  set the divisor #8\n[\nsubtract from the dividend and divisor\n-&gt;+&gt;+&lt;&lt;&gt;&gt;[&lt;&lt;&gt;&gt;-]\nset #10\n+\nif #9 clear #10\n[-][&lt;&gt;&gt;+&lt;&lt;&gt;[-]]\njump back to #8 (divisor possition)\n&lt;&gt;&gt; #11\ncopy to #13\n[&gt;&gt;+&gt;+&lt;&lt;&gt;&gt;[&lt;&lt;&gt;&gt;-]\nset #14\n+\nif #13 clear #14\n[-][&lt;&gt;[-]]\n&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt; #12\nif #12 output value plus offset to ascii 0\n[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]\nsubtract #11 from 10\n++++++++++  #12 is now 10\n- #12\noutput #12 even if it's zero\n++++++++++++++++++++++++++++++++++++++++++++++++.[-]\n&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; #1\ncheck for final number\ncopy #0 to #3\n&gt;&gt;+&gt;+&lt;&lt;&lt;&gt;&gt;&gt;[&lt;&lt;&lt;&gt;&gt;&gt;-]\n&gt;.&gt;.&lt;&lt;&lt;[-]]\n&lt;&gt;+&gt;+&lt;&lt;&gt;&gt;[&lt;&lt;&gt;&gt;-]&lt;&lt;[-]&gt;[-]&lt;&lt;&lt;-\n]\n<\/pre>\n<p>[bf]: http:\/\/www.muppetlabs.com\/~breadbox\/bf\/<br \/>\n[bf-fib]: http:\/\/esoteric.sange.fi\/brainfuck\/bf-source\/prog\/fibonacci.txt<br \/>\n[turing]: http:\/\/goodmath.blogspot.com\/2006\/03\/playing-with-mathematical-machines.html<br \/>\n[minsky]: http:\/\/goodmath.blogspot.com\/2006\/05\/minsky-machine.html<br \/>\n[bf-hard]: http:\/\/www.robos.org\/?bfcomp<br \/>\n[pprimeprime]: http:\/\/en.wikipedia.org\/wiki\/P_prime_prime<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In real life, I&#8217;m not a mathematician; I&#8217;m a computer scientist. Still a math geek, mind you, but what I really do is very much in the realm of applied math, researching how to build systems to help people program. One of my pathological obsessions is programming languages. Since I first got exposed to TRS-80 [&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-73","post","type-post","status-publish","format-standard","hentry","category-pathological-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-1b","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/73","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=73"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}