<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Rough Book &#187; development</title>
	<atom:link href="http://vivin.net/tag/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://vivin.net</link>
	<description>random musings of just another computer nerd</description>
	<lastBuildDate>Tue, 17 Jan 2012 23:32:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CherryBlossom</title>
		<link>http://vivin.net/2010/03/04/cherryblossom/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2010/03/04/cherryblossom/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 02:58:26 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Arts]]></category>
		<category><![CDATA[Haiku]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Poetry]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[brainf*ck]]></category>
		<category><![CDATA[brainfuck]]></category>
		<category><![CDATA[cherryblossom]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[esoteric languages]]></category>
		<category><![CDATA[haiku]]></category>
		<category><![CDATA[interpreters]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[parsers]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[poems]]></category>
		<category><![CDATA[poetry]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1451</guid>
		<description><![CDATA[I&#8217;ve created a project page for the CherryBlossom programming language. You can check it out here. The interpreter is written in perl.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created a project page for the <em><strong>CherryBlossom</strong></em> programming language. You can check it out <a title = "CherryBlossom" href = "http://vivin.net/projects/cherryblossom" target="_self">here</a>. The interpreter is written in perl.</p>
<br /><a href="http://vivin.net/?p=1451#comments" title="Comments on &quot;CherryBlossom&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1451" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1451&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2010/03/04/cherryblossom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1451" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1451" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1451&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>Introducing CherryBlossom</title>
		<link>http://vivin.net/2010/03/02/introducing-cherryblossom/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2010/03/02/introducing-cherryblossom/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 06:06:49 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Arts]]></category>
		<category><![CDATA[Haiku]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Poetry]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[brainf*ck]]></category>
		<category><![CDATA[brainfuck]]></category>
		<category><![CDATA[cherryblossom]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[esoteric languages]]></category>
		<category><![CDATA[haiku]]></category>
		<category><![CDATA[interpreters]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[parsers]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[poems]]></category>
		<category><![CDATA[poetry]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1407</guid>
		<description><![CDATA[Over the past month, I&#8217;ve been working on a new project. It&#8217;s called CherryBlossom, and it&#8217;s a way to write programs using haikus. Strictly speaking, CherryBlossom is a brainfuck analog. I actually spent more time writing the obligatory &#8220;Hello World&#8221; program in CherryBlossom than I did writing the interpreter for the language. The idea behind [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past month, I&#8217;ve been working on a new project. It&#8217;s called <strong><em><a href="http://vivin.net/projects/cherryblossom">CherryBlossom</a></em></strong>, and it&#8217;s a way to write programs using <a href="http://en.wikipedia.org/wiki/Haiku">haikus</a>. Strictly speaking, <strong><em>CherryBlossom</em></strong> is a brainfuck analog. I actually spent more time writing the obligatory &#8220;Hello World&#8221; program in CherryBlossom than I did writing the interpreter for the language. The idea behind <strong><em>CherryBlossom</em></strong> is simple. Brainfuck instructions are mapped to words that convey the essence of the Brainfuck instruction. Of course, this is a little subjective and also a little abstract. </p>
<p>Ultimately, it serves as a way to make program code not just functional, but beautiful and artistic. Thus, we introduce a new criteria to programming. Your code must not only be elegant algorithmically, but must also be poetic and artistic (also, since program code consists of haikus, you need to represent your code in sets of 3 lines with the first and last lines having 5 syllables, and the second line 7. That is, conforming to haiku rules). <strong><em>CherryBlossom</em></strong> serves to blend the programmer and the poet into one entity (hopefully with amazing results).</p>
<p>Here is an example of &#8220;Hello World!&#8221; in<strong> <em>CherryBlossom</em></strong>. I have opted to use a spruced up div tag instead of enclosing my beautiful poem in soulless <em>sourcecode</em> tags.<br />
<span id="more-1407"></span></p>
<div style = "margin-left:auto; margin-right:auto; text-align:center; background-image:url('/wordpress/wp-content/uploads/2010/03/cherryblossom25t.png'); background-repeat:no-repeat; width:350px; font-weight:bold; font-style:italic; font-size:12pt; font-family:times new roman;">
beautiful jasmine<br />
your lovely fragrance heals me<br />
every morning</p>
<p>remembering you,<br />
dreaming of your lovely smile,<br />
when will you come here?</p>
<p>floating butterflies<br />
sunshine and summer flowers<br />
a lovely morning</p>
<p>blossoming hillside<br />
on a fragrant summer day<br />
blooming, flowering.</p>
<p>I can remember<br />
my happy dreams of summer<br />
it was beautiful</p>
<p>flying doves, sunrays<br />
beauty flying in sunshine<br />
rain in the valley.</p>
<p>snow falls in moonlight,<br />
returns to the mountainside.<br />
lovely, beautiful.</p>
<p>view from mountaintop<br />
is a beautiful painting,<br />
in summer sunshine.</p>
<p>the fragrant flowers<br />
and the pretty butterflies<br />
spring by singing creek.</p>
<p>beautiful morning<br />
butterflies by riverside<br />
floating in sunshine.</p>
<p>such a lovely sight,<br />
the valley waterfall is<br />
in the spring sunshine.</p>
<p>sunrays and sunshine,<br />
the butterflies and flowers<br />
loving the new spring.</p>
<p>the pretty flowers<br />
are dreaming of a summer<br />
with the smiling sun.</p>
<p>music from heaven,<br />
is melodious and sweet,<br />
dreamy and happy.</p>
<p>the river is cold<br />
and misty in the moonlight,<br />
in the autumn chill.</p>
<p>winter riverside,<br />
lonely, icy, and chilly<br />
darkening evening</p>
<p>the lonely winter,<br />
barren riverside ahead<br />
a dreaming poet
</p></div>
<p>Trust me, this does print out &#8220;Hello World!&#8221;! You might think I&#8217;m crazy, but I&#8217;m not! Either tomorrow or day after, I&#8217;ll add a new page to the Projects menu and you&#8217;ll see how CherryBlossom works and you will also have access to the interpreter!</p>
<br /><a href="http://vivin.net/?p=1407#comments" title="Comments on &quot;Introducing CherryBlossom&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1407" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1407&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2010/03/02/introducing-cherryblossom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1407" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1407" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1407&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>A brainfuck interpreter in bAdkOde</title>
		<link>http://vivin.net/2010/01/23/a-brainfuck-interpreter-in-badkode/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2010/01/23/a-brainfuck-interpreter-in-badkode/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 21:44:23 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[badkode]]></category>
		<category><![CDATA[brainf*ck]]></category>
		<category><![CDATA[brainfuck]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[turing complete]]></category>
		<category><![CDATA[turing completeness]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1379</guid>
		<description><![CDATA[A few days before I left India, I started writing a brainfuck interpreter in bAdkOde. I finished implemented all the instructions, excepting for looping. I actually finished the code (and fixed all bugs) while I was in the air, flying from Dubai to Los Angeles. Emirates Airlines has power-plugs for your laptop on the seat. [...]]]></description>
			<content:encoded><![CDATA[<p>A few days before I left India, I started writing a <a href="http://www.muppetlabs.com/~breadbox/bf/">brainfuck</a> interpreter in <a href="http://vivin.net/projects/badkode/">bAdkOde</a>. I finished implemented all the instructions, excepting for looping. I actually finished the code (and fixed all bugs) while I was in the air, flying from Dubai to Los Angeles. Emirates Airlines has power-plugs for your laptop on the seat. It&#8217;s pretty sweet!</p>
<p>An interesting thing I noticed was that I couldn&#8217;t perfectly emulate the input instruction. I&#8217;m feeding the brainfuck code to the interpreter from STDIN and so that might be the problem. I&#8217;ve noticed that brainfuck interpreters written in brainfuck have the same problem. You have to specify program input before hand. This is what I&#8217;ve decided to do. You write brainfuck code, and then mark the end of program code by an exclamation mark. After the exclamation mark, you provide any input, and then mark the end of input by another exclamation mark. Programs that do not have any input end with two exclamation marks. After I finished writing the interpreter, I commented it. While I was doing this, I noticed a lack of labels in bAdkOde. So, I decided to update the interpreter to include them. Speaking of which, I really ought to rewrite the interpreter sometime&#8230;</p>
<p>Anyway, here is the code to the interpreter. I&#8217;m <a target="_blank" href="http://vivin.net/pub/bAdkOde/brainfuck_commented.bad">providing</a> a link to it, because the commented version is rather large. But here&#8217;s the expanded (without labels or macros), unformatted version:</p>
<pre class="brush: php">
&gt;3a&gt;1b{!b?b&gt;b[a)b-91b{=b+1[b&gt;1b}+91b-93b{=b-1[b&gt;1b}+93b(b+1a-33b}&gt;0[a+1a&gt;2b&gt;a[b&gt;1b{!b?b&gt;b[a+1a-33b}&gt;1b&gt;a[b&gt;0a&gt;[aa&gt;ab{=a&gt;1a&gt;[ab&gt;3a{![a)a&gt;[aa-62a{=a+1b-30000b)a&gt;ba{+b&gt;1b&gt;[bb)b&gt;0b-1b&gt;0a}{-a+30000b)b&gt;0a}(b(a+62a}+62a-60a{=a-1b)a&gt;1a&gt;[aa-ab&gt;ba{-b&gt;1a&gt;[aa+30000a&gt;ab)b&gt;0b&gt;0a-1a}{+a&gt;1a&gt;[aa+ab)b&gt;0a-1a}(b(a+60a}+60a-43a{=a+1[b+43a}+43a-45a{=a-1[b+45a}+45a-46a{=a&quot;[b+46a}+46a-44a{=a)a&gt;2a&gt;[aa&gt;[a[b&gt;2a+1[a(a+44a}+44a-91a{=a(a)b)a&gt;[bb{=b&gt;0b&gt;1[b{![b(a+1a)a&gt;[aa)a-91a{=a+1[a&gt;1a}+91a-93a{=a-1[a&gt;1a}+93a(a}(a-1a)a&gt;1b}(a(b)a+91a}+91a-93a{=a(a)b)a&gt;[bb{!b&gt;0b&gt;0[b-1[b{![b(a-1a)a&gt;[aa)a-91a{=a+1[a&gt;1a}+91a-93a{=a-1[a&gt;1a}+93a(a}&gt;0b}(a(b)a+93a}+93a(a+1a}&gt;1a&gt;0b}{!b&quot;85&quot;110&quot;109&quot;97&quot;116&quot;99&quot;104&quot;101&quot;100&quot;32&quot;98&quot;114&quot;97&quot;99&quot;107&quot;101&quot;116&quot;115&gt;0b}
</pre>
<p>Also, this is additional proof for Turing Completeness. Yes, I&#8217;m a nerd! <img src='http://vivin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br /><a href="http://vivin.net/?p=1379#comments" title="Comments on &quot;A brainfuck interpreter in bAdkOde&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1379" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1379&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2010/01/23/a-brainfuck-interpreter-in-badkode/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1379" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1379" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1379&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>bAdkOde is Turing Complete</title>
		<link>http://vivin.net/2009/12/26/badkode-is-turing-complete/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/12/26/badkode-is-turing-complete/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 10:26:24 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[badkode]]></category>
		<category><![CDATA[brainf*ck]]></category>
		<category><![CDATA[brainfuck]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[turing complete]]></category>
		<category><![CDATA[turing completeness]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1346</guid>
		<description><![CDATA[In my previous post, I suggested that bAdkOde might be Turing Complete by writing a quine. One of the ways to actually prove Turing Completeness is to try and write an interpreter for another Turing-Complete language in bAdkOde. Another approach involves providing a direct translation from another Turing-Complete language into bAdkOde. Here, I prove the [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://vivin.net/2009/12/25/a-badkode-quine-which-suggests-that-badkode-is-turing-complete/">previous post</a>, I suggested that <a href="http://vivin.net/projects/badkode/">bAdkOde</a> might be <a href="http://en.wikipedia.org/wiki/Turing_complete">Turing Complete</a> by writing a <a href="http://en.wikipedia.org/wiki/Quine_(computing)">quine</a>. One of the ways to actually prove Turing Completeness is to try and write an interpreter for another Turing-Complete language in bAdkOde. Another approach involves providing a direct translation from another Turing-Complete language into bAdkOde. Here, I prove the Turing Completeness of bAdkOde by providing a direct translation from <a href="http://www.muppetlabs.com/~breadbox/bf/">Brainfuck</a> into bAdkOde.<br />
<span id="more-1346"></span><br />
<strong><u>Assumptions</u></strong></p>
<ol>
<li>The <em>a</em> register is our memory pointer.</li>
<li>We initialize the <em>a</em> register to 0.</li>
</ol>
<p><strong><u>Proof</u></strong></p>
<p>We translate Brainfuck to bAdkOde using the following mappings or rules:</p>
<ol>
<li><em>&gt;</em> maps to <em>+1a</em></li>
<li><em>&lt;</em> maps to <em>-1a</em></li>
<li><em>+</em> maps to <em>+1[a</em></li>
<li><em>-</em> maps to <em>-1[a</em></li>
<li><em>.</em> maps to <em>"[a</em></li>
<li><em>,</em> maps to <em>?[a</em></li>
<li><em>[</em> maps to <em>{![a</em></li>
<li><em>]</em> maps to <em>}</em></li>
</ol>
<p><strong><u>Conclusion</u></strong></p>
<p>Since we can completely translate or map Brainfuck, an already Turing-Complete language into bAdkOde, we can say that bAdkOde is also Turing Complete.</p>
<p><strong><u>Translated example</u></strong></p>
<p><strong>helloworld.bf:</strong></p>
<pre class="brush: php">
+++ +++ +++ +
[
    &gt; +++ +++ +
    &gt; +++ +++ +++ +
    &gt; +++
    &gt; +
    &lt;&lt;&lt; &lt; -
]
&gt;++ .
&gt;+.
+++ +++ +.
.
+++ .
&gt;++ .
&lt;&lt;+ +++ +++ +++ +++ ++.
&gt;.
+++ .
--- --- .
--- --- --.
&gt;+.
</pre>
<p><strong>helloworld.bad</strong></p>
<pre class="brush: php">
&gt;0a+1[a+1[a+1[a +1[a+1[a+1[a +1[a+1[a+1[a +1[a
{![a
    +1a +1[a+1[a+1[a +1[a+1[a+1[a +1[a
    +1a +1[a+1[a+1[a +1[a+1[a+1[a +1[a+1[a+1[a +1[a
    +1a +1[a+1[a+1[a
    +1a +1[a
    -1a-1a-1a -1a -1[a
}
+1a+1[a+1[a &quot;[a
+1a+1[a&quot;[a
+1[a+1[a+1[a +1[a+1[a+1[a +1[a&quot;[a
&quot;[a
+1[a+1[a+1[a &quot;[a
+1a+1[a+1[a &quot;[a
-1a-1a+1[a +1[a+1[a+1[a +1[a+1[a+1[a +1[a+1[a+1[a +1[a+1[a+1[a +1[a+1[a&quot;[a
+1a&quot;[a
+1[a+1[a+1[a &quot;[a
-1[a-1[a-1[a -1[a-1[a-1[a &quot;[a
-1[a-1[a-1[a -1[a-1[a-1[a -1[a-1[a&quot;[a
+1a+1[a&quot;[a
</pre>
<p>Here's a quick perl script that I whipped up, to translate Brainfuck to bAdkOde:</p>
<pre class="brush: perl">
#!/usr/bin/perl

 use strict;

 my $terminator = $/;
 undef $/;
 my $bf = &lt;STDIN&gt;;
 $bf =~ s/[^&lt;&gt;\[\]\.,\+\-\s\n]//g;
 $/ = $terminator;

 my $i = 0;

 print &quot;&gt;0a&quot;;

 while($i &lt; length($bf)) {

    my $bf_instruction = substr($bf, $i, 1);

    if($bf_instruction eq &#039;&gt;&#039;) {
       print &quot;+1a&quot;;
    }

    elsif($bf_instruction eq &#039;&lt;&#039;) {
       print &quot;-1a&quot;;
    }

    elsif($bf_instruction eq &#039;+&#039;) {
       print &quot;+1[a&quot;;
    }

    elsif($bf_instruction eq &#039;-&#039;) {
       print &quot;-1[a&quot;;
    }

    elsif($bf_instruction eq &#039;.&#039;) {
       print &quot;\&quot;[a&quot;;
    }

    elsif($bf_instruction eq &#039;,&#039;) {
       print &quot;?[a&quot;;
    }

    elsif($bf_instruction eq &#039;[&#039;) {
       print &quot;{![a&quot;;
    }

    elsif($bf_instruction eq &#039;]&#039;) {
       print &quot;}&quot;;
    }

    else {
       print $bf_instruction;
    }

    $i++;
 }
</pre>
<p><strong><u>Additional proof</u></strong></p>
<p>Since there exist self-interpreters for Brainfuck (i.e., Brainfuck interpreters written <em>in</em> Brainfuck), and since it has been shown that there exists a valid translation from Brainfuck to bAdkOde, it follows that it is possible to write a Brainfuck interpreter in bAdkOde. This provides additional proof for the Turing Completeness of bAdkOde.</p>
<br /><a href="http://vivin.net/?p=1346#comments" title="Comments on &quot;bAdkOde is Turing Complete&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1346" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1346&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/12/26/badkode-is-turing-complete/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1346" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1346" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1346&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>A bAdkOde quine (which suggests that bAdkOde is Turing Complete)</title>
		<link>http://vivin.net/2009/12/25/a-badkode-quine-which-suggests-that-badkode-is-turing-complete/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/12/25/a-badkode-quine-which-suggests-that-badkode-is-turing-complete/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 11:12:41 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[badkode]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[quine]]></category>
		<category><![CDATA[turing complete]]></category>
		<category><![CDATA[turing completeness]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1335</guid>
		<description><![CDATA[On the bAdkOde project page, I mentioned that I didn&#8217;t know whether bAdkOde is Turing Complete (although I suspected it). I also mentioned that if I was able to write a quine in bAdkOde, then it would probably mean that it is Turing Complete. I was able to write one after going through this excellent [...]]]></description>
			<content:encoded><![CDATA[<p>On the bAdkOde <a href="http://vivin.net/projects/badkode/">project page</a>, I mentioned that I didn&#8217;t know whether bAdkOde is <a href="http://en.wikipedia.org/wiki/Turing_completeness">Turing Complete</a> (although I suspected it). I also mentioned that if I was able to write a <a href="http://en.wikipedia.org/wiki/Quine_%28computing%29">quine</a> in bAdkOde, then it would probably mean that it is Turing Complete. I was able to write one after going through this <a href="http://dwcope.freeshell.org/projects/quine/">excellent quine tutorial</a> by Dave Cope.<br />
<span id="more-1335"></span><br />
A quine is basically a program that prints a copy of its source code. Writing a quine seems trivial, but can be, and is in most cases, fiendishly difficult. The quine tutorial that I mentioned earlier describes a rather simple method to create a quine. In any quine, you need to store a representation of part of the source code. This representation is referred to as the <strong>core</strong> or <strong>body</strong>. In the method described in the tutorial, and the method that I used, the core is represented as ASCII codes. In some approaches, the core is represented as a string or character array (which, when it comes down to it, is probably represented in memory as an array of ASCII codes). In the approach that I used, there are two parts to the core. The first part prints out the code for the data structure that will contain a representation of the core, and the second part prints out the actual core. For example, let&#8217;s say I wanted to make a Perl quine. I start off with the core:</p>
<pre class="brush: perl">
 print &quot; \@body = (\n&quot;;
 map { printf &quot;0x%x, &quot;, $_ } @body;
 print &quot; );\n&quot;;
 map { printf &quot;%c&quot;, $_ } @body;
</pre>
<p>Here, you can see that I&#8217;ve decided to use an array called <em>@body</em> to store the ASCII values (in hexadecimal). The first three lines print out the definition for the array that will hold the ASCII values. The last line reads the array, translates the code into actual characters, and prints them out. Now all we have to do is get the hexadecimal codes and create the array. To do that, we use a utility called <em>xxd</em>:</p>
<pre>
vivin@dauntless ~/Projects/code/perl/quine
$ xxd -i quinegen.pl >qhex.pl
</pre>
<p>The output is an array definition in C:</p>
<pre class="brush: c">
unsigned char quinegen_pl[] = {
  0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x5c, 0x40, 0x62,
  0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x28, 0x5c, 0x6e, 0x22, 0x3b, 0x0a,
  0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74,
  0x66, 0x20, 0x22, 0x30, 0x78, 0x25, 0x78, 0x2c, 0x20, 0x22, 0x2c, 0x20,
  0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a,
  0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x29, 0x3b, 0x5c,
  0x6e, 0x22, 0x3b, 0x0a, 0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70,
  0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, 0x22, 0x25, 0x63, 0x22, 0x2c, 0x20,
  0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a
};
unsigned int quinegen_pl_len = 108;
</pre>
<p>We need to change this to valid Perl, and that&#8217;s quite simple:</p>
<pre class="brush: perl">
 @body = (
   0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x5c, 0x40, 0x62,
   0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x28, 0x5c, 0x6e, 0x22, 0x3b, 0x0a,
   0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74,
   0x66, 0x20, 0x22, 0x30, 0x78, 0x25, 0x78, 0x2c, 0x20, 0x22, 0x2c, 0x20,
   0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a,
   0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x29, 0x3b, 0x5c,
   0x6e, 0x22, 0x3b, 0x0a, 0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70,
   0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, 0x22, 0x25, 0x63, 0x22, 0x2c, 0x20,
   0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a
 );
</pre>
<p>We take this and paste it on top of our core:</p>
<pre class="brush: perl">
 @body = (
   0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x5c, 0x40, 0x62,
   0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x28, 0x5c, 0x6e, 0x22, 0x3b, 0x0a,
   0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74,
   0x66, 0x20, 0x22, 0x30, 0x78, 0x25, 0x78, 0x2c, 0x20, 0x22, 0x2c, 0x20,
   0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a,
   0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x29, 0x3b, 0x5c,
   0x6e, 0x22, 0x3b, 0x0a, 0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70,
   0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, 0x22, 0x25, 0x63, 0x22, 0x2c, 0x20,
   0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a
 );
 print &quot; \@body = (\n&quot;;
 map { printf &quot;0x%x, &quot;, $_ } @body;
 print &quot; );\n&quot;;
 map { printf &quot;%c&quot;, $_ } @body;
</pre>
<p>Now the interesting thing here is that this piece of code is not the actual quine. Rather, it <em>generates</em> the quine. But the generated code isn&#8217;t that different from the generator:</p>
<pre class="brush: perl">
 @body = (
0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x5c, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x28, 0x5c, 0x6e, 0x22, 0x3b, 0xa, 0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, 0x22, 0x30, 0x78, 0x25, 0x78, 0x2c, 0x20, 0x22, 0x2c, 0x20, 0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0xa, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x29, 0x3b, 0x5c, 0x6e, 0x22, 0x3b, 0xa, 0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, 0x22, 0x25, 0x63, 0x22, 0x2c, 0x20, 0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0xa,  );
 print &quot; \@body = (\n&quot;;
 map { printf &quot;0x%x, &quot;, $_ } @body;
 print &quot; );\n&quot;;
 map { printf &quot;%c&quot;, $_ } @body;
</pre>
<p>The only difference is the extra comma in the array definition, and the fact that all the ASCII codes are on one line. If you run this perl script, you will get an exact copy of its source code. Now how do we write a quine in bAdkOde? We use a similar approach. First we write the core:</p>
<pre class="brush: php">
&gt;0a
&quot;62&quot;48&quot;97&quot;10
{![a
 &quot;62&#039;[a&quot;91&quot;97&quot;43&quot;49&quot;97
 +1a
}
&quot;10
&gt;0a
{![a
 &quot;[a
 +1a
}
</pre>
<p>To implement a quine in bAdkOde, I decided to store the representation of the core (in decimal ASCII values) in memory starting at location zero. The first line initializes the a register to zero. The second line prints out the string <em>>0a</em> with a newline. This line is analogous to the <em>print " \@body = (\n";</em> line in the perl quine. Within our first loop, we're printing out the actual code that will store the representation of the core in memory. So the first line within the loop prints <em>>ASCII[a+1a</em> where <em>ASCII</em> is the ASCII value of a character from the core. The line is analogous to the <em>printf "0x%x, ", $_</em> line in the perl quine. There is another print statement right outside the first loop, which simply prints a newline. This line is analogous to the <em>print " );\n";</em> line in the perl quine. The second loop performs the actual translation of the ASCII code into the core. Now, just like the perl quine, we use <em>xxd</em>:</p>
<pre>
vivin@dauntless ~/Projects/code/perl/bAdkOde
$ xxd -i quine.bad >qhex.txt
</pre>
<p>After doing this, we get C code that looks like this:</p>
<pre class="brush: c">
unsigned char quine_bad[] = {
  0x3e, 0x30, 0x61, 0x0a, 0x22, 0x36, 0x32, 0x22, 0x34, 0x38, 0x22, 0x39,
  0x37, 0x22, 0x31, 0x30, 0x0a, 0x7b, 0x21, 0x5b, 0x61, 0x0a, 0x20, 0x22,
  0x36, 0x32, 0x27, 0x5b, 0x61, 0x22, 0x39, 0x31, 0x22, 0x39, 0x37, 0x22,
  0x34, 0x33, 0x22, 0x34, 0x39, 0x22, 0x39, 0x37, 0x0a, 0x20, 0x2b, 0x31,
  0x61, 0x0a, 0x7d, 0x0a, 0x22, 0x31, 0x30, 0x0a, 0x3e, 0x30, 0x61, 0x0a,
  0x7b, 0x21, 0x5b, 0x61, 0x0a, 0x20, 0x22, 0x5b, 0x61, 0x0a, 0x20, 0x2b,
  0x31, 0x61, 0x0a, 0x7d, 0x0a
};
unsigned int quine_bad_len = 77;
</pre>
<p>Translating this into bAdkOde is not as straightforward, but it&#8217;s not that difficult either. I removed the first line, and the last two lines from <em>qhex.txt</em> and then used a oneliner:</p>
<pre>
vivin@dauntless ~/Projects/code/perl/bAdkOde
$ cat qhex.txt | perl -e 'chomp($a=&lt;STDIN&gt;); map { print ">" . hex($_) . "[a+1a"; } \
   split(",", $a);' > qdec.txt
</pre>
<p>You end up with this snippet of bAdkOde:</p>
<pre class="brush: php">
&gt;62[a+1a&gt;48[a+1a&gt;97[a+1a&gt;10[a+1a&gt;34[a+1a&gt;54[a+1a&gt;50[a+1a&gt;34[a+1a&gt;52[a+1a&gt;56[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;34[a+1a&gt;49[a+1a&gt;48[a+1a&gt;10[a+1a&gt;123[a+1a&gt;33[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;34[a+1a&gt;54[a+1a&gt;50[a+
1a&gt;39[a+1a&gt;91[a+1a&gt;97[a+1a&gt;34[a+1a&gt;57[a+1a&gt;49[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;34[a+1a&gt;52[a+1a&gt;51[a+1a&gt;34[a+1a&gt;52[a+1a&gt;57[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;10[a+1a&gt;32[a+1a&gt;43[a+1a&gt;49[a+1a&gt;97[a+1a&gt;10[a+1a&gt;125[a+1a&gt;10[
a+1a&gt;34[a+1a&gt;49[a+1a&gt;48[a+1a&gt;10[a+1a&gt;62[a+1a&gt;48[a+1a&gt;97[a+1a&gt;10[a+1a&gt;123[a+1a&gt;33[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;34[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;43[a+1a&gt;49[a+1a&gt;97[a+1a&gt;10[a+1a&gt;125[a+1a&gt;10[a+1a
</pre>
<p>Now all you need to do is copy this snippet into <em>quine.bad</em> (with one minor change) to get a bAdkOde quine:</p>
<pre class="brush: php">
&gt;0a
&gt;62[a+1a&gt;48[a+1a&gt;97[a+1a&gt;10[a+1a&gt;34[a+1a&gt;54[a+1a&gt;50[a+1a&gt;34[a+1a&gt;52[a+1a&gt;56[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;34[a+1a&gt;49[a+1a&gt;48[a+1a&gt;10[a+1a&gt;123[a+1a&gt;33[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;34[a+1a&gt;54[a+1a&gt;50[a+
1a&gt;39[a+1a&gt;91[a+1a&gt;97[a+1a&gt;34[a+1a&gt;57[a+1a&gt;49[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;34[a+1a&gt;52[a+1a&gt;51[a+1a&gt;34[a+1a&gt;52[a+1a&gt;57[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;10[a+1a&gt;32[a+1a&gt;43[a+1a&gt;49[a+1a&gt;97[a+1a&gt;10[a+1a&gt;125[a+1a&gt;10[
a+1a&gt;34[a+1a&gt;49[a+1a&gt;48[a+1a&gt;10[a+1a&gt;62[a+1a&gt;48[a+1a&gt;97[a+1a&gt;10[a+1a&gt;123[a+1a&gt;33[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;34[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;43[a+1a&gt;49[a+1a&gt;97[a+1a&gt;10[a+1a&gt;125[a+1a&gt;10[a+1a
&gt;0a
&quot;62&quot;48&quot;97&quot;10
{![a
 &quot;62&#039;[a&quot;91&quot;97&quot;43&quot;49&quot;97
 +1a
}
&quot;10
&gt;0a
{![a
 &quot;[a
 +1a
}
</pre>
<p>The small change I had to make, was to add <em>>0a</em> at the beginning. If you run this bAdkOde program, it will print its source code as output. So there you have it. A bAdkOde quine, which proves that bAdkOde is Turing Complete. I have to thank <a href="http://dwcope.freeshell.org/">Dave Cope</a> for his quine tutorial, without which it would have been extremely difficult for me to write a bAdkOde quine!</p>
<p><strong>Update (12/26/2009)</strong></p>
<p>Dave mentioned that writing a quine only <em>suggests</em> that a language is Turing Complete, but not that it is. He suggested that I write an interpreter for <a href = "http://www.muppetlabs.com/~breadbox/bf/">Brainfuck</a> which would then prove that bAdkOde is Turing Complete. That was actually my next project!</p>
<p><strong>Update (12/26/2009)</strong></p>
<p>I&#8217;ve been able to provide a <a href="http://vivin.net/2009/12/26/badkode-is-turing-complete/">direct translation</a> of Brainfuck into bAdkOde, which proves the Turing Completeness of bAdkOde.</p>
<br /><a href="http://vivin.net/?p=1335#comments" title="Comments on &quot;A bAdkOde quine (which suggests that bAdkOde is Turing Complete)&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1335" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1335&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/12/25/a-badkode-quine-which-suggests-that-badkode-is-turing-complete/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1335" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1335" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1335&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>if-else in bAdkOde</title>
		<link>http://vivin.net/2009/12/16/if-else-in-badkode/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/12/16/if-else-in-badkode/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 02:11:27 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[badkode]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[esoteric languages]]></category>
		<category><![CDATA[interpreters]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[parsers]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1321</guid>
		<description><![CDATA[I was talking to my CSE 200 (my first CS class at ASU) professor Richard Whitehouse about bAdkOde and he (rightly) pointed out that it didn&#8217;t have an explicit selection statement. He also said that unless I wanted it to be really ugly I&#8217;d need to have a selection statement. However, since I was going [...]]]></description>
			<content:encoded><![CDATA[<p>I was talking to my CSE 200 (my first CS class at ASU) professor Richard Whitehouse about <strong><a href="http://vivin.net/projects/badkode/">bAdkOde</a></strong> and he (rightly) pointed out that it didn&#8217;t have an explicit selection statement. He also said that unless I wanted it to be really ugly I&#8217;d need to have a selection statement. However, since I was going for ugly I figured that I&#8217;d just emulate the operation of an <em>if</em> and an <em>if-else</em> with the existing <em>while</em> statement.</p>
<p>If you know assembly, then you know that a <em>while</em> is simply a set of statements wrapped with a conditional branch at the top and a backwards branch at the bottom (or in other words, an <em>if</em> with a <em>goto</em> at the end. A <em>do-while</em> is simply a set of statements with a conditional branch (at the bottom) that branches to the top of the loop. In fact, in assembly programming there really aren&#8217;t any <em>for loops</em> or <em>while loops</em>. These keywords are simply abstractions and syntactic sugar. In <strong>bAdkOde</strong>, you can implement an <em>if</em> with the existing <em>while</em> statement if you explicitly make it break out of the loop. For example, let&#8217;s say that we want to check whether the user entered the character &#8220;0&#8243;:</p>
<pre class="brush: php">
?a
-48a
# print a line break
&quot;10
# if a is zero
{=a
 # print the string &quot;zero&quot;
 &quot;122&quot;101&quot;114&quot;111&quot;10
 # set the a register to a non-zero value so that we can break out of the loop
 &gt;1a
}
</pre>
<p>I knew there was a way to implement an <em>if-else</em> with just <em>while</em> statements but I didn&#8217;t remember exactly how. Then my friend and co-worker Juan reminded me that I needed two variables. In our case, we need to use two registers:</p>
<pre class="brush: php">
?a
-48a
# copy the value of a into b
&gt;ab
&quot;10
# if a is zero
{=a
 # print the string &quot;zero&quot;
 &quot;122&quot;101&quot;114&quot;111&quot;10
 # set the a register to a non-zero value so that we can break out of the loop
 &gt;1a
}
# if the top loop failed, it means that b (which holds the same value as a) is
# non-zero and so we can enter this block.
# if the top loop was successful, it means that b (which holds the same value
# as a) is zero and so we won&#039;t enter this block. Hence, the second block acts
# as an &#039;else&#039;
{!b
 # print the string &quot;non-zero&quot;
 &quot;110&quot;111&quot;110&quot;45&quot;122&quot;101&quot;114&quot;111&quot;10
 # zero out the b register
 &gt;0b
}
</pre>
<p>Yes, quite ugly. But that&#8217;s what I&#8217;m going for! <img src='http://vivin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br /><a href="http://vivin.net/?p=1321#comments" title="Comments on &quot;if-else in bAdkOde&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1321" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1321&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/12/16/if-else-in-badkode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1321" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1321" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1321&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>bAdkOde: An Esoteric Language</title>
		<link>http://vivin.net/2009/12/13/badkode-an-esoteric-language/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/12/13/badkode-an-esoteric-language/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 01:53:43 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[badkode]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[esoteric languages]]></category>
		<category><![CDATA[interpreters]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[parsers]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1317</guid>
		<description><![CDATA[I&#8217;ve added another project to the projects page. It&#8217;s called bAdkOde, an interpreter for an esoteric language that I designed. The very first incarnation of bAdkOde was written in Java and I actually posted it (or made a blog entry about it) over 8 years ago. For some reason I took it down. Probably because [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve added another project to the projects page. It&#8217;s called <strong>bAdkOde</strong>, an interpreter for an <a title="Esoteric language" href="http://en.wikipedia.org/wiki/Esoteric_language" target="_blank">esoteric language</a> that I designed. The very first incarnation of <strong>bAdkOde</strong> was written in Java and I actually <a title="First post about bAdkOde" href="http://vivin.net/2001/04/07/new-interface-and-badkode/" target="_blank">posted it </a>(or made a blog entry about it) over 8 years ago. For some reason I took it down. Probably because I stopped working on it. Anyway, I redesigned the language and wrote an interpreter for it in Perl about 4 or 5 years ago. I finally got around to posting it. <a title="bAdkOde" href="http://vivin.net/projects/badkode/" target="_self">Check out</a> the project page for more details. Let me know what you think.</p>
<br /><a href="http://vivin.net/?p=1317#comments" title="Comments on &quot;bAdkOde: An Esoteric Language&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1317" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1317&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/12/13/badkode-an-esoteric-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1317" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1317" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1317&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>An update to the Grinder testing-framework</title>
		<link>http://vivin.net/2009/12/07/an-update-to-the-grinder-testing-framework/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/12/07/an-update-to-the-grinder-testing-framework/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 18:34:59 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Jython]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[grinder]]></category>
		<category><![CDATA[jython]]></category>
		<category><![CDATA[performance testing]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[the grinder]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1258</guid>
		<description><![CDATA[Mukesh alerted me to a problem with the Perl conversion script (that converts the XML produced by the Grinder recorder into a Jython file). It wasn&#8217;t parsing all the parameters in a GET request properly. I&#8217;ve fixed the bug and uploaded a new version of the script. You can download it here.]]></description>
			<content:encoded><![CDATA[<p>Mukesh <a target = "_blank" href = "http://vivin.net/2009/09/16/writing-performance-tests-in-grinder-using-a-framework/#comment-1113">alerted</a> me to a problem with the Perl conversion script (that converts the XML produced by the Grinder recorder into a Jython file). It wasn&#8217;t parsing all the parameters in a GET request properly. I&#8217;ve fixed the bug and uploaded a new version of the script. You can download it <a href='http://vivin.net/wp-content/uploads/2009/09/xmlToJython.pl'>here</a>.</p>
<br /><a href="http://vivin.net/?p=1258#comments" title="Comments on &quot;An update to the Grinder testing-framework&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1258" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1258&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/12/07/an-update-to-the-grinder-testing-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1258" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1258" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1258&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>JSTL, instanceof, and hasProperty</title>
		<link>http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 04:12:30 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[custom tags]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[instanceof]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[jstl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[taglibs]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1233</guid>
		<description><![CDATA[I&#8217;ve been doing a little bit of JSTL over the past week, especially custom tags. I&#8217;ve written custom tags in Grails before, and there you use actual Groovy code. I guess this was how custom tags used to be written (in Java), but now you can can build your own custom tags using the standard [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing a little bit of <a href="http://java.sun.com/products/jsp/jstl/">JSTL</a> over the past week, especially custom tags. I&#8217;ve written custom tags in Grails before, and there you use actual Groovy code. I guess this was how custom tags used to be written (in Java), but now you can can build your own custom tags using the standard tag library. The standard tag library is still pretty useful when it comes to building custom tags. Since it&#8217;s not straight Java, it forces you think really hard about your logic. You don&#8217;t want to put any business or application logic in your tag, and you want to restrict everything to view or presentation logic. A side effect of it not being Java is that if you want to do anything extremely complicated, you&#8217;re probably better off writing the tag in Java (making sure that you don&#8217;t let any business logic creep in).</p>
<p>While writing my own custom tag, I noticed that although <em>instanceof</em> is a reserved word in the JSTL EL (expression language), it is not supported as an operator. The reason I wanted to use the <em>instanceof</em> operator is that I have an attribute that could either be a <em>List</em> or a <em>Map</em> and depending on the type, I wanted to do different things.</p>
<p>Another thing I was trying to do, was to inspect the incoming object to see if it had a certain property (reflection). JSTL uses reflection so that you can access the properties of an object via dot notation, if they follow the JavaBean naming-convention. However, there was no way for me to see if an object had a certain property. To solve both these problems, I wrote my own JSTL functions.<br />
<span id="more-1233"></span><br />
The first function I wrote was one that performed the <em>instanceof</em> operation. I created a class called <em>TagUtils</em> that contained static methods that returned primitive types (like boolean, String, or Integer). <em>instanceof</em> presents a special challenge because you can&#8217;t have the second parameter be dynamic. For example, assuming that you have an object named <em>acura</em> that&#8217;s an instance of the class <em>Car</em> and a String named <em>className</em> that holds the value &#8220;<em>Car</em>&#8220;, you can&#8217;t do <em><strong>acura</strong> instanceof <strong>className</strong></em>. You have to use reflection and create a <em>Class</em> object using the <em>forName</em> static method and then check to see if <em>acura</em> is an instance by using the <em>isInstance</em> method.</p>
<p>The second function I wrote is the <em>hasProperty</em> function which uses reflection to check whether the supplied object has a particular property. To be precise, I don&#8217;t explicitly check for the existence of the object directly. Rather, I check and see if there is a getter for that property. For example, if the property is called <em>firstName</em>, then there should be a getter called <em>getFirstName()</em>.</p>
<p>The code for the functions looks like this:</p>
<pre class="brush: java">
package util.tag;

public class TagUtils {

    //Checks to see if Object &#039;o&#039; is an instance of the class in the string &quot;className&quot;
    public static boolean instanceOf(Object o, String className) {
        boolean returnValue;

        try {
            returnValue = Class.forName(className).isInstance(o);
        }

        catch(ClassNotFoundException e) {
            returnValue = false;
        }

        return returnValue;
    }

    //Checks to see if Object &#039;o&#039; has a property specified in &quot;propertyName&quot;
    public static boolean hasProperty(Object o, String propertyName) {
        boolean methodFound = false;
        int i = 0;

        Class myClass = o.getClass();
        String methodName = &quot;get&quot; + propertyName.toUpperCase().charAt(0) + propertyName.substring(1);
        Method[] methods = myClass.getMethods();

        while(i &lt; methods.length &amp;&amp; !methodFound) {
            methodFound = methods[i].getName().compareTo(methodName) == 0;
            i++;
        }

        return methodFound;
    }
}
</pre>
<p><del datetime="2009-12-12T21:35:27+00:00">For the <em>hasProperty</em> function, you can see that I used the <em>getMethod</em> method. The second argument is an array of parameter types. Since the getter accepts no parameters, we pass in an empty array (of type <em>Class</em>).</del></p>
<p>Using exceptions in business logic is really bad, because it slows down the JVM. So the rendering will also become really slow if there are a lot of exceptions being thrown. To fix this problem, I used the <em>getMethods</em> method, which returns an array of <em>Method</em> objects. I then search the array to see if the getter I want, exists.</p>
<p>After you create your functions, you have to put them in a <em>tld</em> file. I created a one called <em>tagutils.tld</em> that I put in <em>WEB-INF</em>:</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;taglib xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd&quot;
    version=&quot;2.1&quot;&gt;
    &lt;tlib-version&gt;1.0&lt;/tlib-version&gt;
    &lt;short-name&gt;function&lt;/short-name&gt;
    &lt;uri&gt;http://tagutils&lt;/uri&gt;
    &lt;function&gt;
        &lt;name&gt;instanceOf&lt;/name&gt;
        &lt;function-class&gt;util.tag.TagUtils&lt;/function-class&gt;
        &lt;function-signature&gt;boolean instanceOf(java.lang.Object, java.lang.String)&lt;/function-signature&gt;
    &lt;/function&gt;
    &lt;function&gt;
        &lt;name&gt;hasProperty&lt;/name&gt;
        &lt;function-class&gt;util.tag.TagUtils&lt;/function-class&gt;
        &lt;function-signature&gt;boolean hasProperty(java.lang.Object, java.lang.String)&lt;/function-signature&gt;
    &lt;/function&gt;
&lt;/taglib&gt;
</pre>
<p>Once you create that file, you can use your new functions in your JSP files. To test the <em>hasProperty</em> function, I created a simple class called <em>Person</em>:</p>
<pre class="brush: java">
package domain;

public class Person {
    private String firstName;
    private String lastName;

    public Person(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public String toString() {
        return firstName + &quot; &quot; + lastName;
    }
}
</pre>
<p>Now I put it all together:</p>
<pre class="brush: xhtml">
&lt;%@ taglib prefix=&quot;function&quot; uri=&quot;http://tagutils&quot;%&gt;
&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;

&lt;%@ page import=&quot;java.util.Map&quot; %&gt;
&lt;%@ page import=&quot;java.util.LinkedHashMap&quot; %&gt;
&lt;%@ page import=&quot;java.util.List&quot; %&gt;
&lt;%@ page import=&quot;java.util.ArrayList&quot; %&gt;
&lt;%@ page import=&quot;domain.Person&quot; %&gt;
&lt;%
    Map&lt;String, String&gt; myMap = new LinkedHashMap&lt;String, String&gt;();
    pageContext.setAttribute(&quot;myMap&quot;, myMap);

    List&lt;Person&gt; myList = new ArrayList&lt;Person&gt;();
    pageContext.setAttribute(&quot;myList&quot;, myList);

    pageContext.setAttribute(&quot;person&quot;, new Person(&quot;Holly&quot;, &quot;Hoo&quot;));
%&gt;

myMap is an instance of Map:
&lt;b&gt;
 &lt;c:choose&gt;
   &lt;c:when test=&quot;${function:instanceOf(myMap, &#039;java.util.Map&#039;)}&quot;&gt;true&lt;/c:when&gt;
   &lt;c:otherwise&gt;false&lt;/c:otherwise&gt;
  &lt;/c:choose&gt;
&lt;/b&gt;&lt;br/&gt;
myList is an instance of List:
&lt;b&gt;
 &lt;c:choose&gt;
  &lt;c:when test=&quot;${function:instanceOf(myList, &#039;java.util.List&#039;)}&quot;&gt;true&lt;/c:when&gt;
  &lt;c:otherwise&gt;false&lt;/c:otherwise&gt;
 &lt;/c:choose&gt;
&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;

myMap is an instance of List:
&lt;b&gt;
 &lt;c:choose&gt;
  &lt;c:when test=&quot;${function:instanceOf(myMap, &#039;java.util.List&#039;)}&quot;&gt;true&lt;/c:when&gt;
  &lt;c:otherwise&gt;false&lt;/c:otherwise&gt;&lt;/c:choose&gt;
&lt;/b&gt;&lt;br/&gt;
myList is an instance of Map:
&lt;b&gt;
 &lt;c:choose&gt;
  &lt;c:when test=&quot;${function:instanceOf(myList, &#039;java.util.Map&#039;)}&quot;&gt;true&lt;/c:when&gt;
  &lt;c:otherwise&gt;false&lt;/c:otherwise&gt;
 &lt;/c:choose&gt;
&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;

Person has a property called firstName:
&lt;b&gt;
 &lt;c:choose&gt;
  &lt;c:when test=&quot;${function:hasProperty(person, &#039;firstName&#039;)}&quot;&gt;true&lt;/c:when&gt;
  &lt;c:otherwise&gt;false&lt;/c:otherwise&gt;
 &lt;/c:choose&gt;
&lt;/b&gt;&lt;br/&gt;
Person has a property called lastName:
&lt;b&gt;
 &lt;c:choose&gt;
  &lt;c:when test=&quot;${function:hasProperty(person, &#039;lastName&#039;)}&quot;&gt;true&lt;/c:when&gt;
  &lt;c:otherwise&gt;false&lt;/c:otherwise&gt;
 &lt;/c:choose&gt;
&lt;/b&gt;&lt;br /&gt;
Person has a property called id:
&lt;b&gt;
 &lt;c:choose&gt;
  &lt;c:when test=&quot;${function:hasProperty(person, &#039;id&#039;)}&quot;&gt;true&lt;/c:when&gt;
  &lt;c:otherwise&gt;false&lt;/c:otherwise&gt;
 &lt;/c:choose&gt;
&lt;/b&gt;&lt;br /&gt;
</pre>
<p><em><strong>Note</strong>: I have used a scriptlet in the above example simple to demonstrate the usage of the functions. The use of scriptlets in JSP is bad practice since it probably means that you are putting your business logic in your JSP. The proper place for such code is in a Controller or a Service.</em></p>
<p>As you can see from the above example, the usage is pretty simple. If everything went well, the output should look something like this:</p>
<blockquote><p>
myMap is an instance of Map: <strong>true</strong><br />
myList is an instance of List: <strong>true</strong></p>
<p>myMap is an instance of List: <strong>false</strong><br />
myList is an instance of Map: <strong>false</strong></p>
<p>Person has a property called firstName: <strong>true</strong><br />
Person has a property called lastName: <strong>true</strong><br />
Person has a property called id: <strong>false</strong>
</p></blockquote>
<p><em><b>Note</b>: Using the JSP above, the <em>true</em> and <em>false</em> values will actually be on separate lines. I broke the code up in my example for readability. In my actual code, The whole logic expression is in one line.</em></p>
<p>One important thing to note is that when you use the <em>instanceOf</em> function, you have to provide the <strong>fully-qualified class-name</strong>. Otherwise, the method will return <em>false</em>.</p>
<p><strong>UPDATE</strong></p>
<p><strong>thetoolman</strong> suggested some improvements that uses <span style = "font-family: courier new; font-weight: bold">BeanInfo</span> instead of the reflection API:</p>
<pre class="brush: java">
public class TagUtils {

    public static boolean instanceOf(Object o, String className) {
        if (o == null || className == null) {
            return false;
        }

        try {
            return Class.forName(className, false, Thread.currentThread().getContextClassLoader()).isInstance(o);
        }

        catch (ClassNotFoundException e) {
            return false;
        }
    }

    public static boolean hasProperty(Object o, String propertyName) {
        if (o == null || propertyName == null) {
            return false;
        }

        BeanInfo beanInfo;
        try {
            beanInfo = java.beans.Introspector.getBeanInfo(o.getClass());
        }

        catch (IntrospectionException e) {
            return false;
        }

        for(final PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {

            if (propertyName.equals(pd.getName())) {
                return true;
            }
        }
        return false;
    }
}
</pre>
<h4>References</h4>
<ol>
<li><a href="http://stackoverflow.com/questions/1076315/jstl-check-if-property-doesnt-exist"> JSTL: check if property doesn&#8217;t exist (stackoverflow.com)</a></li>
<li><a href="http://mindprod.com/jgloss/instanceof.html">instanceof: Java Glossary (mindprod.com)</a></li>
<li><a href="http://java.sun.com/javase/6/docs/api/java/lang/Class.html">Class (Java Platform SE 6)</a></li>
</ol>
<br /><a href="http://vivin.net/?p=1233#comments" title="Comments on &quot;JSTL, instanceof, and hasProperty&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1233" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1233&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/12/04/jstl-instanceof-and-hasproperty/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1233" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1233" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1233&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>About Me and Projects</title>
		<link>http://vivin.net/2009/11/22/about-me-and-projects/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/11/22/about-me-and-projects/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 23:28:52 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[my website]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1220</guid>
		<description><![CDATA[I finally got around to adding pages to my blog. I&#8217;ve added an &#8220;About Me&#8221; page and a &#8220;Projects&#8221; page. The &#8220;Projects&#8221; page is similar to the one I had on the old site. I&#8217;ve migrated one project (Sulekha) over. Will be moving the second one (FXCalendar) over soon and I&#8217;m also going to try [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to adding pages to my blog. I&#8217;ve added an &#8220;About Me&#8221; page and a &#8220;Projects&#8221; page. The &#8220;Projects&#8221; page is similar to the one I had on the old site. I&#8217;ve migrated one project (Sulekha) over. Will be moving the second one (FXCalendar) over soon and I&#8217;m also going to try and add another one to the list.</p>
<br /><a href="http://vivin.net/?p=1220#comments" title="Comments on &quot;About Me and Projects&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1220" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1220&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/11/22/about-me-and-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1220" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1220" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1220&#38;type=feed" medium="image" />
	</item>
	</channel>
</rss>

