{"id":12,"date":"2008-10-21T23:48:44","date_gmt":"2008-10-21T23:48:44","guid":{"rendered":"http:\/\/hodgestar.za.net\/blog\/?p=12"},"modified":"2008-10-22T08:02:51","modified_gmt":"2008-10-22T08:02:51","slug":"whitespace","status":"publish","type":"post","link":"https:\/\/hodgestar.za.net\/blog\/2008\/10\/whitespace\/","title":{"rendered":"Whitespace"},"content":{"rendered":"<p>I&#8217;ve got a soft spot for <a href=\"http:\/\/en.wikipedia.org\/wiki\/Stack-oriented_programming_language\">stack-based languages<\/a> &#8212; and not just because the <a href=\"http:\/\/www.python.org\/doc\/2.5.2\/lib\/bytecodes.html\">bytecode for my current favourite language<\/a> happens to be one (albeit one with a fairly extensive set of relatively complex operations). Another soft spot is toy languages, so it shouldn&#8217;t be surprising that I&#8217;ve been meaning to play around with something like <a href=\"http:\/\/en.wikipedia.org\/wiki\/Whitespace_(programming_language)\">Whitespace<\/a> or <a href=\"http:\/\/en.wikipedia.org\/wiki\/Brainfuck\">Brainfuck<\/a> for a while. All I lacked was an <a href=\"http:\/\/www.catb.org\/~esr\/writings\/cathedral-bazaar\/cathedral-bazaar\/ar01s02.html\">itch<\/a> [1,2] and yesterday I got <a href=\"http:\/\/blog.charlvn.za.net\/2008\/10\/converting-tabs-to-spaces.html\">one<\/a>.<\/p>\n<p>In 2008, if you&#8217;re going to write code to convert tabs to spaces, there really seems to be only one choice. Not only is Whitespace one of the few languages to fully support <a href=\"http:\/\/en.wikipedia.org\/wiki\/Literate_programming\">literate programming<\/a> but it also has <a href=\"http:\/\/en.wikipedia.org\/wiki\/Steganography\">advanced security<\/a> built right into the syntax and the very name is tailored to the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Problem_domain_analysis\">problem domain<\/a> at hand.<\/p>\n<p>So, armed with a <a href=\"http:\/\/compsoc.dur.ac.uk\/whitespace\/tutorial.php\">tutorial<\/a>, an <a href=\"http:\/\/yagni.com\/whitespace\/index.html\">assembler<\/a> and a <a href=\"http:\/\/compsoc.dur.ac.uk\/archives\/whitespace\/2007-December\/000065.html\">Python Whitespace interpreter<\/a> [3], I set to work. An hour or two later I had a result, which you can find <a href=\"http:\/\/locustforge.hodgestar.za.net\/trac\/browser\/hodgestar\/WhitespaceCode\/tabs2spaces\">here<\/a>. It can be called using something like:<\/p>\n<blockquote><p>echo -e &#8220;a\\tb c&#8221; | python main.py ..\/tabs2spaces\/tabs2spaces.ws<\/p><\/blockquote>\n<p>or<\/p>\n<blockquote><p>echo -e &#8220;a\\tb c&#8221; | python main.py ..\/tabs2spaces\/comment.embedded<\/p><\/blockquote>\n<p>for the text embedded version (here main.py refers to Phillip Bradbury&#8217;s interpreter).<\/p>\n<p>I opted for Phillip&#8217;s Python version of the Whitespace interpreter rather than the more standard Haskell one, because Phillip&#8217;s one sensibly reports -1 when the end of standard input is reached, while the Haskell one raises an error. I had to make one minor change to Phillip&#8217;s interpreter to stop parsing the source file once the end-of-program token had been reached, which allows it to process <a title=\"See the embed section.\" href=\"http:\/\/compsoc.dur.ac.uk\/whitespace\/tools.php\">embedded<\/a> Whitespace where the text extends beyond the program source. The modified version is available <a href=\"http:\/\/locustforge.hodgestar.za.net\/trac\/browser\/hodgestar\/WhitespaceCode\/pbradbury\">here<\/a> under the GPL.<\/p>\n<p><strong>[1]<\/strong> &#8220;good work&#8221; may be something of a misnomer in this case.<\/p>\n<p><strong>[2]<\/strong> And I&#8217;m dubious as to whether this constitutes &#8220;knowing what to write&#8221;.<\/p>\n<p><strong>[3]<\/strong> What better way of implementing one stack-based language than with another stack-based language?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve got a soft spot for stack-based languages &#8212; and not just because the bytecode for my current favourite language happens to be one (albeit one with a fairly extensive set of relatively complex operations). Another soft spot is toy languages, so it shouldn&#8217;t be surprising that I&#8217;ve been meaning to play around with something [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[14],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-tech","tag-whitespace"],"_links":{"self":[{"href":"https:\/\/hodgestar.za.net\/blog\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hodgestar.za.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hodgestar.za.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hodgestar.za.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hodgestar.za.net\/blog\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":6,"href":"https:\/\/hodgestar.za.net\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":14,"href":"https:\/\/hodgestar.za.net\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions\/14"}],"wp:attachment":[{"href":"https:\/\/hodgestar.za.net\/blog\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hodgestar.za.net\/blog\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hodgestar.za.net\/blog\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}