{"id":216,"date":"2006-11-17T12:08:09","date_gmt":"2006-11-17T12:08:09","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2006\/11\/17\/friday-pathological-programming-quine-madness-with-muriel\/"},"modified":"2006-11-17T12:08:09","modified_gmt":"2006-11-17T12:08:09","slug":"friday-pathological-programming-quine-madness-with-muriel","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2006\/11\/17\/friday-pathological-programming-quine-madness-with-muriel\/","title":{"rendered":"Friday Pathological Programming: Quine Madness with Muriel"},"content":{"rendered":"<p>Due to work stuff, I&#8217;m very busy this week, and I don&#8217;t have time to write a detailed<br \/>\npathological language post, so I chose something that doesn&#8217;t take a lot of explanation, but<br \/>\nwhich is delightfully twisted. It&#8217;s a language called [Muriel](http:\/\/web.archive.org\/web\/20021205092706\/http:\/\/demo.raww.net\/muriel\/), aka<br \/>\nthe *&#8221;Monumentally Useless ReIterative Execution Language&#8221;.<br \/>\nMuriel is based on the idea of [*quines*](http:\/\/www.nyx.net\/~gthompso\/quine.htm). A quine for a programming language is a program in that language which produces itself as output.  Quines are<br \/>\nconsidered interesting puzzles in some circles, which has led to generation of huge collections of quines in just about every imaginable programming language. Follow the link above to see one such collection. Muriel takes things a step further: instead of quines being an interesting (if pointless) challenge, in<br \/>\nMuriel, they&#8217;re an essential part of the language!<\/p>\n<p><!--more--><br \/>\nTo give you a sense of what a quine looks like, here&#8217;s a fairly verbose but easy-to-follow quine in Java:<br \/>\npublic class Myself {<br \/>\nstatic String[] me = {<br \/>\n&#8220;public class Myself {&#8220;,<br \/>\n&#8221;  static String[] me = {&#8220;,<br \/>\n&#8221;  };&#8221;,<br \/>\n&#8221;  static char quote =&#8221;,<br \/>\n&#8221;  public static void main(String argv[]) {&#8220;,<br \/>\n&#8221;    for (int i = 0; i &lt; 2; i++)&quot;,<br \/>\n&quot;      System.out.println(me[i]);&quot;,<br \/>\n&quot;    for (int i = 0; ; ) {&quot;,<br \/>\n&quot;      for (int j = 0; j &lt; 4; j++)&quot;,<br \/>\n&quot;        System.out.print(&#039; &#039;);&quot;,<br \/>\n&quot;      System.out.print(quote + me[i] + quote);&quot;,<br \/>\n&quot;      if (++i == me.length) {&quot;,<br \/>\n&quot;        System.out.println();&quot;,<br \/>\n&quot;        break;&quot;,<br \/>\n&quot;      }&quot;,<br \/>\n&quot;      System.out.println(&#039;,&#039;);&quot;,<br \/>\n&quot;    }&quot;,<br \/>\n&quot;    for (int i = 2; i &lt;= 3; i++)&quot;,<br \/>\n&quot;      System.out.println(me[i]);&quot;,<br \/>\n&quot;    for (int i = 0; i &lt; 4; i++)&quot;,<br \/>\n&quot;      System.out.print(&#039; &#039;);&quot;,<br \/>\n&quot;    System.out.print(&#039;&#039;&#039;);&quot;,<br \/>\n&quot;    System.out.print(quote);&quot;,<br \/>\n&quot;    System.out.print(&#039;&#039;&#039;);&quot;,<br \/>\n&quot;    System.out.println(&#039;;&#039;);&quot;,<br \/>\n&quot;    for (int i = 4; i &lt; me.length; i++)&quot;,<br \/>\n&quot;      System.out.println(me[i]);&quot;,<br \/>\n&quot;  }&quot;,<br \/>\n&quot;}&quot;<br \/>\n};<br \/>\nstatic char quote =<br \/>\n&#039;&quot;&#039;;<br \/>\npublic static void main(String argv[]) {<br \/>\nfor (int i = 0; i &lt; 2; i++)<br \/>\nSystem.out.println(me[i]);<br \/>\nfor (int i = 0; ; ) {<br \/>\nfor (int j = 0; j &lt; 4; j++)<br \/>\nSystem.out.print(&#039; &#039;);<br \/>\nSystem.out.print(quote + me[i] + quote);<br \/>\nif (++i == me.length) {<br \/>\nSystem.out.println();<br \/>\nbreak;<br \/>\n}<br \/>\nSystem.out.println(&#039;,&#039;);<br \/>\n}<br \/>\nfor (int i = 2; i &lt;= 3; i++)<br \/>\nSystem.out.println(me[i]);<br \/>\nfor (int i = 0; i &lt; 4; i++)<br \/>\nSystem.out.print(&#039; &#039;);<br \/>\nSystem.out.print(&#039;&#039;&#039;);<br \/>\nSystem.out.print(quote);<br \/>\nSystem.out.print(&#039;&#039;&#039;);<br \/>\nSystem.out.println(&#039;;&#039;);<br \/>\nfor (int i = 4; i &lt; me.length; i++)<br \/>\nSystem.out.println(me[i]);<br \/>\n}<br \/>\n}<br \/>\nA more twisted example is the following C which is *almost* a one-liner (it would be a one-liner<br \/>\nif it weren&#039;t for the fact that the author wanted it to be *valid* ANSI C).<br \/>\n#include<br \/>\nmain(){char*c=&#8221;\\&#8221;#include%cmain(){char*c=%c%c%c%.102s%cn%c<br \/>\n;printf(c+2,c[102],c[1],*c,*c,c,*c,c[1]);exit(0);}n&#8221;;printf(c+2,c[10<br \/>\n2],c[1],*c,*c,c,*c,c[1]);exit(0);}<br \/>\nSo, what does this stuff have to do with Muriel?<br \/>\nThe only control structure in Muriel is &#8220;evaluate string as program&#8221;. What that means is that the<br \/>\nonly way to make a loop in Muriel is to create a subprogram which is a quine for the loop. Without<br \/>\nquining, Muriel is a simple rotten programming language that isn&#8217;t even turing complete. *With* quining, Muriel is *still* a simple rotten programming language &#8211; but it *is* turing complete.<br \/>\nOk, time for a quick look at the language.<br \/>\n* There are two kinds of variables in Muriel: string-valued variables and integer-valued variables. String valued variables are written as upper case letters; integer variables as lower case letters.<br \/>\n* Assignment in Muriel is written with the colon character, as in `a:3` or `B:&#8221;Foobar&#8221;`.<br \/>\n* The &#8220;.&#8221; character is a print statement, which only outputs strings; e.g., `.A` or `.&#8221;Hello there&#8221;`.<br \/>\n* The &#8220;@&#8221; character is the execute-string-as-program command. It takes a string, and executes<br \/>\nthat string as a Muriel program, *replacing the currently executing program*. There is *no*<br \/>\ncommunication between the caller and the callee &#8211; no parameters, no shared variables: everything<br \/>\nhas to be coded into the string being executed.<br \/>\n* Muriel of course includes the usual arithmetic operators for integers: `+`, `-`, `*`, `&gt;`, `0*&amp;Z&#8221;;<br \/>\nZ:&#8221;b:&#8221;+$b+Q+|Q+&#8221;&#8221;;nR:&#8221;&#8221;+|R+R;<br \/>\n@%Z,0,b&gt;0*&amp;Z<br \/>\nThe first couple of lines are pretty simple: set b to 99, print out a verse of the song, decrement b.<br \/>\nThe sixth, seventh, and eighth lines of the program are the nightmare: a mess which really just<br \/>\nquines up the program, but with the decremented value of b. Finally, in the 9th line, it checks if &#8220;b&#8221; is 0; if not, then it executes the quine that it generated.<br \/>\nFor a *real* nightmare,<br \/>\n[this](http:\/\/web.archive.org\/web\/20020705102824\/demo.raww.net\/muriel\/bub.txt) is basically a<br \/>\nbrainfuck interpreter written in Muriel. (It&#8217;s not *quite* BF; it&#8217;s a variant called &#8220;Bub&#8221;. In order<br \/>\nto avoid needed to do the position recording of the BF loop operator, it uses a conditional &#8220;goto&#8221;<br \/>\nstatement; translating BF programs to Bub is trivial.)<br \/>\nP:&#8221;000100120022003200420052006200720082009202360110012201320142015201620172018201920201021301170230024502510262027202820292030203120322042603400352036203720382039104030347042004320445045204620472048204920502051205250535054205520562057506160593059706110622063206420652066206720682069207960710072207320742075207610773071707900805081108220832084208520862087208820892090209120922102609400952096209720982099210011013094710201035104110521062107210821092110211121122121611401152116211721181119311471210122512321242125212651273128312931303131313231335134313531363137313831393140314131425146614431447146114721482149215021512152215321542164615601572158215921602161116231567164016521665170616831687170217121722173217421752176217721782179218051818&#8243;;<br \/>\nM:&#8221;0  &#8220;;<br \/>\nc:0;<br \/>\nI:&#8221; &#8220;;<br \/>\nd:0;<br \/>\nA:&#8221;??????????n??n?????????????????? !&#8221;#$%&amp;'()*+,-.\/0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~&#8221;;<br \/>\nw:4;<br \/>\nN:(%P,c*w,(c*w)+w);S:(%N,w-1,w);<br \/>\nQ:&#8221;P:&#8221;&#8221;+|P+&#8221;&#8221;;nM:&#8221;&#8221;+M+&#8221;&#8221;;nc:&#8221;+$c+&#8221;;nI:&#8221;&#8221;+|I+&#8221;&#8221;;nd:&#8221;+$d+&#8221;;nA:&#8221;&#8221;+|A+&#8221;&#8221;;nw:&#8221;+$w+&#8221;;nc:c+1;nl:#(%M,d,d+3);n&#8221;;<br \/>\nG:&#8221;d:d-3;&#8221;;<br \/>\nQ:Q+(%G,0,&amp;G*(#S=0));<br \/>\nG:&#8221;d:d+3;M:M+(%&#8221;0  &#8220;,0,(d=&amp;M)*3);&#8221;;<br \/>\nQ:Q+(%G,0,&amp;G*(#S=1));<br \/>\nG:&#8221;;F:(%($(l+1)+&#8221;   &#8220;),0,3);M:(%M,0,d)+F+(%M,d+3,&amp;M);&#8221;;<br \/>\nQ:Q+(%G,0,&amp;G*(#S=2));<br \/>\nG:&#8221;F:(%($(l-1)+&#8221;   &#8220;),0,3);M:(%M,0,d)+F+(%M,d+3,&amp;M);&#8221;;<br \/>\nQ:Q+(%G,0,&amp;G*(#S=3));<br \/>\nH:&#8221;I:~;&#8221;;<br \/>\nG:(%H,0,&amp;H*(&amp;I=0))+&#8221;M:(%M,0,d)+(%I,0,3)+(%M,d+3,&amp;M);I:(%I,3,&amp;I);&#8221;;<br \/>\nQ:Q+(%G,0,&amp;G*(#S=4));<br \/>\nG:&#8221;.(%A,l,l+1);&#8221;;<br \/>\nQ:Q+(%G,0,&amp;G*(#S=5));<br \/>\nj:#(%N,0,w-1);<br \/>\nG:&#8221;c:(c*(1-(l=0)))+(&#8220;+$j+&#8221;*(l=0));&#8221;;<br \/>\nQ:Q+(%G,0,&amp;G*(#S=6));<br \/>\nG:&#8221;c:(c*(l=0))+(&#8220;+$j+&#8221;*(1-(l=0)));&#8221;;<br \/>\nQ:Q+(%G,0,&amp;G*(#S=7));<br \/>\nG:&#8221;@&#8221; &#8220;&#8221;;<br \/>\nQ:Q+(%G,0,&amp;G*(#S=8));<br \/>\nR:&#8221;N:(%P,c*w,(c*w)+w);nS:(%N,w-1,w);nQ:&#8221;P:\\&#8221;&#8221;+|P+&#8221;\\&#8221;;\\nM:\\&#8221;&#8221;+M+&#8221;\\&#8221;;\\nc:&#8221;+$c+&#8221;;\\nI:\\&#8221;&#8221;+|I+&#8221;\\&#8221;;\\nd:&#8221;+$d+&#8221;;\\nA:\\&#8221;&#8221;+|A+&#8221;\\&#8221;;\\nw:&#8221;+$w+&#8221;;\\nc:c+1;\\nl:#(%M,d,d+3);\\n&#8221;;nG:&#8221;d:d-3;&#8221;;nQ:Q+(%G,0,&amp;G*(#S=0));nG:&#8221;d:d+3;M:M+(%\\&#8221;0  \\&#8221;,0,(d=&amp;M)*3);&#8221;;nQ:Q+(%G,0,&amp;G*(#S=1));nG:&#8221;F:(%($(l+1)+\\&#8221;   \\&#8221;),0,3);M:(%M,0,d)+F+(%M,d+3,&amp;M);&#8221;;nQ:Q+(%G,0,&amp;G*(#S=2));nG:&#8221;F:(%($(l-1)+\\&#8221;   \\&#8221;),0,3);M:(%M,0,d)+F+(%M,d+3,&amp;M);&#8221;;nQ:Q+(%G,0,&amp;G*(#S=3));nH:&#8221;I:~;&#8221;;nG:(%H,0,&amp;H*(&amp;I=0))+&#8221;M:(%M,0,d)+(%I,0,3)+(%M,d+3,&amp;M);I:(%I,3,&amp;I);&#8221;;nQ:Q+(%G,0,&amp;G*(#S=4));nG:&#8221;.(%A,l,l+1);&#8221;;nQ:Q+(%G,0,&amp;G*(#S=5));nj:#(%N,0,w-1);nG:&#8221;c:(c*(1-(l=0)))+(&#8220;+$j+&#8221;*(l=0));&#8221;;nQ:Q+(%G,0,&amp;G*(#S=6));nG:&#8221;c:(c*(l=0))+(&#8220;+$j+&#8221;*(1-(l=0)));&#8221;;nQ:Q+(%G,0,&amp;G*(#S=7));nG:&#8221;@\\&#8221; \\&#8221;&#8221;;nQ:Q+(%G,0,&amp;G*(#S=8));nR:&#8221;&#8221;;<br \/>\nZ:&#8221;&#8221;;nX:Q+R+|R+&#8221;\\&#8221;;Z:\\&#8221;&#8221;+|Z+Z;n@X&#8221;;<br \/>\nX:Q+R+|R+&#8221;&#8221;;Z:&#8221;&#8221;+|Z+Z;<br \/>\n@X<br \/>\nDon&#8217;t ask me to explain that mess. I&#8217;ve got a faint clue of how it works, but there&#8217;s not a chance in hell that I could explain it in any coherent way. In fact, I&#8217;m pretty sure that *no one* can explain it in a coherent way, because it&#8217;s fundamentally incoherent.<br \/>\nBut fun, in a twisted way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Due to work stuff, I&#8217;m very busy this week, and I don&#8217;t have time to write a detailed pathological language post, so I chose something that doesn&#8217;t take a lot of explanation, but which is delightfully twisted. It&#8217;s a language called [Muriel](http:\/\/web.archive.org\/web\/20021205092706\/http:\/\/demo.raww.net\/muriel\/), aka the *&#8221;Monumentally Useless ReIterative Execution Language&#8221;. Muriel is based on the idea [&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-216","post","type-post","status-publish","format-standard","hentry","category-pathological-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-3u","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/216","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=216"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/216\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}