{"id":297,"date":"2007-02-02T09:51:05","date_gmt":"2007-02-02T09:51:05","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2007\/02\/02\/pathological-programming-as-pathological-cooking\/"},"modified":"2007-02-02T09:51:05","modified_gmt":"2007-02-02T09:51:05","slug":"pathological-programming-as-pathological-cooking","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2007\/02\/02\/pathological-programming-as-pathological-cooking\/","title":{"rendered":"Pathological Programming as Pathological Cooking"},"content":{"rendered":"<p> I&#8217;ve had a long, difficult week, so I&#8217;ve decided to pick something pointlessly<br \/>\npathological for today. It&#8217;s a remarkably goofy language called <a href=\"http:\/\/www.p-nand-q.com\/humor\/programming_languages\/gplz\/gplz_chef.html\">&#8220;Chef&#8221;<\/a>, designed by David Morgan-Mar, in which programs are <em>recipes<\/em>. Since aside from being a programming language<br \/>\nnutjob, I&#8217;m also a pretty good chef, combining two of my favorite things naturally has<br \/>\nsome appeal &#8211; particularly when done in a pointlessly twisted way.<\/p>\n<p><!--more--><\/p>\n<p> I said that programs in chef are recipes. I wasn&#8217;t joking. The structure of a Chef<br \/>\nprogram is a recipe title, then an ingredients list, then preparation instructions, and<br \/>\nfinally serving information.<\/p>\n<p> The recipe title is the first line of the program. It gives the recipe a name,<br \/>\nwhich can later be used to call it as a sub-recipe. After the title, you can have<br \/>\ncomments &#8211; which don&#8217;t need to be marked in any way. The real meat of the program<br \/>\nstarts with the ingredients.<\/p>\n<p> The ingredients section starts with the keyword &#8220;Ingredients.&#8221; (period mandatory).<br \/>\nAfter that, it&#8217;s one ingredient per line. Every ingredient must be unique, and every<br \/>\none must have a numerical quantity. The ingredients are, essentially, your variables.\n<\/p>\n<p> After the ingredients are a blank line, followed by the keyword &#8220;Method.&#8221;. Each line after &#8220;Method.&#8221; is a program statement. All of the things you can do are described in terms of statements that look like recipe steps. Computations are done using <em>mixing bowls<\/em>, which are basically stacks. A sampling of statements:<\/p>\n<dl>\n<dt> <code>Put <em>ingredient<\/em> into <em>nth<\/em> mixing bowl<\/code><\/dt>\n<dd> Puts the ingredient on top of the specified bowl.<\/dd>\n<dt> <code>Add <em>ingredient<\/em> to the <em>nth<\/em> mixing bowl<\/code><\/p>\n<dt>\n<dd> Adds the value of the ingredient to the value on top in the specified bowl.&lt;\/dd<\/p>\n<dt> <code>Remove  <em>ingredient<\/em> from <em>nth<\/em> mixing bowl.<\/code><\/dt>\n<dd> Subtract the value of the ingredient from the top of the bowl.<\/dd>\n<dt> <code>Fold <em>ingredient<\/em> into <em>nth<\/em> mixing bowl.<\/code><\/dt>\n<dd> remove the value on top of the specified bowl, and store it in <em>ingredient<\/em>. <\/dd>\n<dt> <code>Combine <em>ingredient<\/em> with <em>nth<\/em> mixing bowl.<\/code> <\/dt>\n<dd> Multiplies the top of the bowl by the ingredient.<\/li>\n<dt> <code>Liquify <em>ingredient<\/em><\/code><\/dt>\n<dd> Convert the specified ingredient to be interpreted as a character rather than an integer.<\/dd>\n<dt> <code>verb <em>ingredient<\/em>. ... verb until <em>ingredient<\/em> verbed<\/code><\/dt>\n<dd> Looping construct. This is basically the same as the BrainFuck looping<br \/>\nconstruct. If the ingredient named at the loop start is greater than 0, then<br \/>\nthe loop is run; if the ingredient named at the loop end is greater than<br \/>\n0, then repeat the loop again.<\/dd>\n<dt><code>set aside<\/code><\/dt>\n<dd> Exit from the innermost loop.<\/dd>\n<dt> <code>Pour contents of the <em>nth<\/em> mixing bowl into the <em>mth<\/em> baking dish<\/code><\/dt>\n<dd> Transfer from a mixing bowl to a baking dish. Things in baking<br \/>\ndishes can be printed out at the end of the program.<\/dd>\n<dt><code>Serve with <em>recipe-name<\/em><\/code><\/dt>\n<dd>Call another recipe as a subroutine. The new recipe will be prepared by<br \/>\na &#8220;sous chef&#8221; who gets <em>copies<\/em> of all of the mixing bowls in use<br \/>\nby the calling chef &#8211; but changes to the bowls don&#8217;t affect the calling<br \/>\nchef&#8217;s bowls. When the sub-recipe complete, the contents of its first bowl<br \/>\nare added to the calling chef&#8217;s first bowl.<\/dd>\n<dt><code>Refrigerate <em>number<\/em> hours<\/code><\/dt>\n<dd>Halt execution. If this is a sub-recipe, return to the caller. The number<br \/>\nis optional &#8211; if it&#8217;s mentioned, then print out the values of the first<br \/>\n<em>number<\/em> baking dishes.<\/dd>\n<dt>\n<\/dl>\n<p> And so on. These are the basics; there are more instructions in the same vein. For<br \/>\nthe complete list, check the <a href=\"http:\/\/www.p-nand-q.com\/humor\/programming_languages\/gplz\/gplz_chef.html\">Chef<br \/>\npage.<\/a><\/p>\n<p> After the main instructions, the program ends with a &#8220;<code>Serves<br \/>\n<em>number<\/em><\/code>&#8221; statement, that says how many portions the recipe produces. The<br \/>\nserves statement prints out the content of the first <em>number<\/em> baking dishes.<\/p>\n<hr \/>\n<p> So, here&#8217;s a nice little hello world recipe. I wouldn&#8217;t particularly want to<br \/>\neat it, but it does the job. <\/p>\n<pre>\nHello World Souffle.\nThis recipe prints the immortal words \"Hello world!\", in a\nbasically brute force way. It also makes a lot of food for one person.\nIngredients.\n72 g haricot beans\n101 eggs\n108 g lard\n111 cups oil\n32 zucchinis\n119 ml water\n114 g red salmon\n100 g dijon mustard\n33 potatoes\nMethod.\nPut potatoes into the mixing bowl.\nPut dijon mustard into the mixing bowl.\nPut red salmon into the mixing bowl.\nPut oil into the mixing bowl.\nPut water into the mixing bowl.\nPut zucchinis into the mixing bowl.\nPut oil into the mixing bowl.\nPut lard into the mixing bowl.\nPut lard into the mixing bowl.\nPut eggs into the mixing bowl.\nPut haricot beans into the mixing bowl.\nLiquify contents of the mixing bowl.\nPour contents of the mixing bowl into the baking dish.\nServes 1.\n<\/pre>\n<p> The ingredients are the unicode values of the characters of the hello world<br \/>\nmessage. As a mnemonic aid, the names of each of the ingredients start with the letter<br \/>\nthat their value corresponds to &#8211; so &#8220;Haricot beans&#8221; is the letter &#8220;H&#8221;. The program dumps all of them into the first mixing bowl. Then the contents of the bowl are  liquified (changing them from numbers to characters, and turning the contents bowl<br \/>\ninto a string.). Finally, the liquified bowl contents are moved to a baking dish, so<br \/>\nthat they can be output, and the &#8220;serves&#8221; statement outputs the string in the baking<br \/>\ndish. Voila! Hello world.<\/p>\n<p> A much more interesting recipe: generating fibonacci numbers. This gives you more of an idea of just how to do actual computations. Alas, it doesn&#8217;t bother to print<br \/>\nthem. One of the main weaknesses of Chef is that you can only really output<br \/>\nthings when a recipe exits. If you wanted to print the Fibonacci numbers as you<br \/>\ngenerated them, you&#8217;d have to add a sub-recipe to do it.<\/p>\n<pre>\nFibonacci Al-Dente.\nThis will print the first 20 fibonacci numbers.\nIngredients.\n1 egg\n1 butter\n20 carots\n1 banana\nMethod.\nHeat the carots. Put egg into the 1 mixing bowl.\nPut butter into the 2 mixing bowl. Put carots into the 3 mixing bowl.\nLiquify the 2 mixing bowl. Clean the 4 mixing bowl.\nPut egg into the 4 mixing bowl. Add butter to the 4 mixing bowl.\nClean the 2 mixing bowl. Pour contents of the 1 mixing bowl into the 2\nmixing bowl.\nClean the 1 mixing bowl. Pour contents of the 4 mixing bowl into the 1\nmixing bowl.\nRemove banana from 3 mixing bowl. Fold carots into 3 mixing bowl.\nFold butter into the 2 mixing bowl. Fold egg into the 1 mixing bowl.\nRepeat until the carots stink.\n<\/pre>\n<p> It&#8217;s a simple program, but cute. Here&#8217;s how it works:<\/p>\n<ol>\n<li> We start with egg=1, butter=1, carots=20, and banana=1.<\/li>\n<li> &#8220;Heat the carrots&#8221; starts a loop, which use carots as a loop index.<\/li>\n<li> Egg, butter, and carots go into separate mixing bowls.<\/li>\n<li> Then there&#8217;s a sort-of elaborate shuffling, which adds the last two<br \/>\nfibonacci numbers together, and rotates contents around so that<br \/>\nwe still have the first two fibonacci numbers in egg and butter. (Banana<br \/>\nis just an index used for decrementing carots.)<\/li>\n<li> And repeat until carots=0.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve had a long, difficult week, so I&#8217;ve decided to pick something pointlessly pathological for today. It&#8217;s a remarkably goofy language called &#8220;Chef&#8221;, designed by David Morgan-Mar, in which programs are recipes. Since aside from being a programming language nutjob, I&#8217;m also a pretty good chef, combining two of my favorite things naturally has some [&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-297","post","type-post","status-publish","format-standard","hentry","category-pathological-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-4N","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/297","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=297"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/297\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}