<?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; Projects</title>
	<atom:link href="http://vivin.net/category/nerdy-stuff/computers-nerdy-stuff/programming-and-development-computers-nerdy-stuff/projects-programming-and-development-computers-nerdy-stuff/feed/" rel="self" type="application/rss+xml" />
	<link>http://vivin.net</link>
	<description>random musings of just another computer nerd</description>
	<lastBuildDate>Wed, 02 May 2012 18:20:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Regula: An annotation-based form-validator written in Javascript</title>
		<link>http://vivin.net/2010/03/30/regula-an-annotation-based-form-validator-written-in-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2010/03/30/regula-an-annotation-based-form-validator-written-in-javascript/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 15:16:27 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[annotation-based form-validation]]></category>
		<category><![CDATA[annotation-based validation]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[bean-validation]]></category>
		<category><![CDATA[form-validation]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript form-validation]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[regula]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1477</guid>
		<description><![CDATA[Regula is an annotation-based form-validation framework written in Javascript. There already exist a few frameworks that address form-validation in Javascript, but I have found them to be somewhat lacking. I have thought about writing one of my own for some time, but I honestly had no idea what form it would or should take. I [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>Regula</em></strong> is an annotation-based form-validation framework written in Javascript. There already exist a few frameworks that address form-validation in Javascript, but I have found them to be somewhat lacking. I have thought about writing one of my own for some time, but I honestly had no idea what form it would or should take. I knew that I wanted to make one that was easy to use, flexible, and easily extensible (custom validation rules). I finally got an idea as to the form my framework should take, when I was looking at <a href="http://www.hibernate.org/">Hibernate</a> <a href="http://docs.jboss.org/hibernate/stable/validator/reference/en/html_single/">bean-validation</a>. I like the fact that you can set constraints by using annotations like <em>@NotNull</em> or  <em>@NotEmpty</em>. That way, when you look at the bean, you are immediately aware of the constraints attached to it. I wanted to do something similar in HTML.<br />
<span id="more-1477"></span><br />
Enter HTML5. HTML5 supports and endorses <a href="http://dev.w3.org/html5/spec/dom.html#embedding-custom-non-visible-data">custom attributes</a> in HTML tags. Purists may scream &#8220;No!&#8221;, but I think it is a useful feature. However, like all features it has the potential for abuse. But that&#8217;s another topic entirely. Anyway, I started thinking &#8211; what if I could use a custom attribute to specify the constraints? Then I could use Javascript to identify those constraints and then enforce them during validation. What I was thinking of, was to do something like this:</p>
<pre class="brush: html">
&lt;input id = &quot;myInput&quot;
         type = &quot;text&quot;
         data-constraints = &#039;@NotEmpty @IsNumeric @Between(min=1, max=5)&#039;&gt;
</pre>
<p>That bit of code describes a text box which cannot be empty, and which expects a numeric value between 1 and 5. With this basic design in mind, I started working on my framework. It took me about a week of on-and-off work (maybe 3 days actual work) but I&#8217;ve come up with something that is, in my humble opinion, a flexible and easy to use framework. I plan to document the use of this library/framework more thoroughly, but this post should serve as a gentle introduction to the framework and its features.</p>
<p>In <em><strong>Regula</strong></em> (which, by the way, means &#8220;rule&#8221; in Latin) form elements (input elements or even the form elements) can have constraints attached to them in a similar fashion to the example I described earlier. There is a small difference, however:</p>
<pre class="brush: html">
&lt;input id = &quot;myInput&quot;
         class = &quot;regula-validation&quot;
         type = &quot;text&quot;
         data-constraints = &#039;@NotEmpty @IsNumeric @Between(min=1, max=5)&#039;&gt;
</pre>
<p>As you can see, I use a class name of <em>regula-validation</em> which tells the framework that this input element has constraints attached to it. The reason I did this was for efficiency reasons. It&#8217;s much more efficient to grab all elements that have a class name of <em>regula-validation</em> than walking the whole document tree to search for nodes that have a <em>data-constraints</em> attribute.</p>
<p>After you annotate the input elements with their constraints, you&#8217;re halfway there already! All you have to do after that is add a script tag for the framework:</p>
<pre class="brush: html">
  &lt;script type = &quot;text/javascript&quot; src=&quot;regula.js&quot;&gt;&lt;/script&gt;
</pre>
<p>And then add the necessary Javascript to validate the form (example uses jQuery):</p>
<pre class="brush: javascript">
jQuery(document).ready(function() {
    // must call this first. The best place would be in an
    // onload handler. This function looks for elements with
    // a class name of &quot;regula-validation&quot; and binds the
    // appropriate constraints to the elements
    regula.bind(); 

    jQuery(&quot;#myForm&quot;).submit(function() {
        // this functions performs the actual validation
        var validationResults = regula.validate();

        for(var index in validationResults) {
             var validationResult = validationResults[index];
             alert(validationResult.message);
        }
    });
});
</pre>
<p>That&#8217;s pretty much all there is to it. More advanced uses of the framework don&#8217;t deviate that much from this pattern. Compared to other form-validation frameworks (that I&#8217;ve seen), validation will not stop on the first failing element. The <em>validate</em> function runs through every input element and validates it against the constraints bound to that element, and returns an array of &#8220;validation results&#8221;. Each &#8220;validation result&#8221; element in the array has the following properties:</p>
<ul>
<li><em><strong>constraintName</strong></em> &#8211; the name of the failing constraint</li>
<li><em><strong>custom</strong></em> &#8211; a flag that says whether this is a custom constraint or not</li>
<li><em><strong>constraintParameters</strong></em> &#8211; An array of objects that represents the parameters passed to this constraint (defined in the HTML. For example <em>@Max(max=5)</em>, where you have a parameter who&#8217;s name is <em>max</em> and who&#8217;s value is <em>5</em>. There&#8217;s a little more to this, but like I said, this is supposed to be a gentle introduction <img src='http://vivin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</li>
<li><em><strong>receivedParameters</strong></em> &#8211; A hash (organized such that the name of the parameter is the key, and the value is well, the value) of parameters that the validator function received (helpful when you have a custom validator).
<li><em><strong>failingElements</strong></em> &#8211; An array containing references to the actual input element or elements (in the case of form-specific constraints) that failed the constraint.</li>
<li><em><strong>message</strong></em> &#8211; The error message.</li>
</ul>
<br /><a href="http://vivin.net/?p=1477#comments" title="Comments on &quot;Regula: An annotation-based form-validator written in Javascript&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1477" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1477&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2010/03/30/regula-an-annotation-based-form-validator-written-in-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1477" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1477" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1477&#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>Sulekha: A text-based Markov-chain generator</title>
		<link>http://vivin.net/2007/07/05/sulekha-a-textbased-markovchain-generator/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2007/07/05/sulekha-a-textbased-markovchain-generator/#comments</comments>
		<pubDate>Thu, 05 Jul 2007 22:37:26 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[mark v shaney]]></category>
		<category><![CDATA[markov]]></category>
		<category><![CDATA[markov chain]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[probability]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[stochastic]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=378</guid>
		<description><![CDATA[I&#8217;ve finished work on the projects page. Sometimes I&#8217;ll have a passing interest in something that leads me to write some code for fun. Yes, you read right. I like to code&#8230; for fun. Anyway, this is something I&#8217;ve done ever since I started programming way back in 1991. I&#8217;ve written a bunch of cool [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finished work on the <a target = "_blank" href = "http://vivin.net/projects/">projects</a> page. Sometimes I&#8217;ll have a passing interest in something that leads me to write some code for fun. Yes, you read right. I like to code&#8230; for fun. Anyway, this is something I&#8217;ve done ever since I started programming way back in 1991. I&#8217;ve written a bunch of cool little programs over the years. Most of these have been throwaway scripts that I wrote just to &#8220;see what would happen&#8221;. A few of these, however, have had some serious effort put into them. I&#8217;ve decided to showcase these on my site. Hopefully people will find them interesting <img src='http://vivin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p>The project I&#8217;ve just uploaded is called <em>Sulekha</em>, and is a text-based Markov-chain generator. You can check it out <a target = "_blank" href = "http://vivin.net/projects/sulekha">here</a>. The comments for this journal entry are mirrored on the <em>Sulekha</em> project page, so anything you post here will be visible there (and vice versa). Let me know what you think. Oh, and it&#8217;s interactive so you can generate your own text-based Markov-chains too!</p>
<br /><a href="http://vivin.net/?p=378#comments" title="Comments on &quot;Sulekha: A text-based Markov-chain generator&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?378" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=378&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2007/07/05/sulekha-a-textbased-markovchain-generator/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?378" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?378" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=378&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>Artificial Life &#8211; some preliminary findings</title>
		<link>http://vivin.net/2004/10/19/artificial-life-some-preliminary-findings/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2004/10/19/artificial-life-some-preliminary-findings/#comments</comments>
		<pubDate>Tue, 19 Oct 2004 22:55:25 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[artificial life simulator]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding for fun]]></category>
		<category><![CDATA[eden]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=312</guid>
		<description><![CDATA[I fnished my artificial life simulator over the weekend, and I have been running simulations on it. There were a few bugs initially that I quickly fixed. My initial simulations gave me some inexplicable &#8220;population explosion&#8221;. For example, in one cycle I would have 31 creatures and in the next cycle I would suddenly have [...]]]></description>
			<content:encoded><![CDATA[<p>I fnished my artificial life simulator over the weekend, and I have been running simulations on it. There were a few bugs initially that I quickly fixed. My initial simulations gave me some inexplicable &#8220;population explosion&#8221;. For example, in one cycle I would have 31 creatures and in the next cycle I would suddenly have around 9,000. It didn&#8217;t make very much sense until I analyzed the log files.</p>
<p>If any of you remember, I mentioned earlier that my &#8220;creatures&#8221; are nothing more than assembly programs. Each of these instructions (and parameters) translate into a bit pattern. Changes in the bit patterns lead to changes in the behaviour of the creature.</p>
<p>One of the instructions is a &#8220;reproduce instruction&#8221;. This prompts the creature to create a copy of itself, with possible mutations. The instruction has a parameter that tells the creature how many copies to create. During the course of the simulation, certain creatures evolved with the reproduce instruction as their first instruction.</p>
<p>My supervisor program (God program) runs one instruction of every creature during one cycle (sort of like an pre-emptive multitasking operating system). If a creature happens to reproduce during the current cycle, then the supervisor program will execute the child&#8217;s instructions as well in that current cycle. This led to an interesting situation. When the mutant that had the reproduce instruction as the first instruction reproduced, its child (if it didn&#8217;t have a mutation that changed the instruction) also had the reproduce instruction as the first instruction. So the supervisor program would run the child, and the child would reproduce with a similar offspring. This went on until a mutant that did not have a &#8220;reproduce instruction&#8221; as the first instruction, evolved. As you can see, this is what led to the population explosion. I corrected this problem by adding &#8220;sexual maturity&#8221; and &#8220;reproductive energy threshold&#8221; parameters to the creatures. Basically, a creature can reproduce only if it has been in existence for a certain number of cycles, and if its current energy is above its reproductive energy threshold. This got rid of the population explosion problem.</p>
<p>My simulations gave me some other interesting results. One of the instructions that I have is a MOV instruction. This instruction moves a creature from one cell in the two-dimensional array to another cell. There is a variant of this instruction, known as the MOVA instruction. In the MOV instruction, if the creature tries to move to an occupied cell, it will retreat to its original position. However, in the MOVA instruction the creature will try to kill (and subsequently eat) the occupant if the destination cell is occupied. I had created a creature that simply ate, reproduced, and moved to different cells. I noted that after many generations, this creature had evolved into an aggressive one, that would eat, reproduce, and move aggressively (MOVA) into other cells. That was rather interesting!</p>
<p>I also saw natural selection at work. When I corrected my population explosion problem, I made it so that the reproductive threshold of a creature was higher than its initial (starting) energy. Over the course of many cycles, I saw that the creatures evolved such that the initial energy would be very high, and that their reproductive threshold would be very low. In additon, their reproductive age was lowered. I thought that my creatures were having it too easy, so I modified my code to make reproduction a costly instruction. After running my simulation, I noticed the opposite! Now the creatures evolved such that the reproductive energy threshold would be much higher than their initial energy. It would seem that the creatures wanted to build up enough energy to where they would be able to reproduce successfuly.</p>
<p>There is also one <em>very interesting</em> behaviour that I noticed. I provide branch instructions in my instruction set. A creature can branch to any part of its code. In addition, I also have a Decrement and Branch instruction that is useful for iterative loops. One of my creatures evolved a clever strategy. It would decrement and branch <em>into the middle</em> of the branch instruction. When I analyzed the code, I noticed in doing so, the creature was performing a MOVA instruction in <em>fewer</em>  bytes than writing an explicit MOVA instruction. It also had the added benefit of performing the MOVA instruction in an iterative fashion so that it could travel around the two-dimensional array. There was a reason for this kind of behaviour though. A creature consumes energy when it performs an instruction, and the energy consumption is proportional to its code size, so it is amazing, but not surprising that such behaviour could arise.</p>
<p>There is still more work that I need to do. I am thinking of giving my creatures some &#8220;memory&#8221; in the form of stack and RAM. They will have some Store, Load, Push and Pop instructions whereby they can write to and read from memory.  Also, I am thinking of adding some more &#8220;registers&#8221;. Right now, the creatures have two count registers for performing iterative loops. My reason for adding more is this &#8211; I want the creatures to be able to act on the data in memory. For example, I can provide instructions that allow the creature to check the status of a particular cell, like if it is occupied, how much food it has, and so on. The creature can load data into the registers, and then use these registers as arguments for the cell checking instructions. This way I am hoping that my creatures will be able to evolve some rudimentary form of &#8220;intelligence&#8221;, or &#8220;intelligent&#8221; behavior.  This will also increase my instruction set. Right now, if a mutation results in an invalid instruction, the creature dies when it tries to execute it. Actually, that reminds me &#8211; I had creatures that evolved with invalid instructions, but they had also evolved branch instructions that would <strong>jump over</strong> the invalid section of code!</p>
<p>Most of these complex behaviours aren&#8217;t that surprising when you consider natural selection&#8230; it is only err&#8230; natural that such behaviour should arise!</p>
<p>Well I guess that&#8217;s all I have for now. I might make a separate page for this project where I can describe this project in more detail. I&#8217;ll post more updates here after I run more simulations.</p>
<br /><a href="http://vivin.net/?p=312#comments" title="Comments on &quot;Artificial Life &#8211; some preliminary findings&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?312" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=312&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2004/10/19/artificial-life-some-preliminary-findings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?312" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?312" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=312&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>Intel and Artificial Life</title>
		<link>http://vivin.net/2004/09/17/intel-and-artificial-life/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2004/09/17/intel-and-artificial-life/#comments</comments>
		<pubDate>Fri, 17 Sep 2004 20:42:17 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[artificial life]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding for fun]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=295</guid>
		<description><![CDATA[This is my fourth day at Intel. I think I will enjoy working here. I haven&#8217;t done much yet though, and I still don&#8217;t know exactly what it is I am supposed to be doing. I tested some 140 chips yesterday, but that wasn&#8217;t too much work. My supervisor is out until Tuesday, so until [...]]]></description>
			<content:encoded><![CDATA[<p>This is my fourth day at Intel. I think I will enjoy working here. I haven&#8217;t done much yet though, and I still don&#8217;t know exactly what it is I am supposed to be doing. I tested some 140 chips yesterday, but that wasn&#8217;t too much work. My supervisor is out until Tuesday, so until then I am doing some odd jobs and reading up some documentation about the platforms and tools we use. I am excited to be working here. It looks like it&#8217;s going to be hard work, but I think it will also be fun.</p>
<p>Now about the Artificial Life. I have written up some specs on an Artificial Life program. This is different from earlier ones. I am implementing the &#8220;creatures&#8221; like assembly programs. This code is their &#8220;DNA&#8221;. It describes how they behave. A &#8220;God Program&#8221; executes one instruction of each &#8220;creature&#8221; and moves on to the next. Sort of like a pre-emptive multitasking operating system. The creatures all live in a two-dimensional area of memory. They can reproduce, and there is chance of error during reproduction.</p>
<p>I think I was going about it the wrong way earlier. I was trying to describe behaviour through variables and through discrete quantities. Now, I represent each creature as a bit-pattern &#8211; exactly like an assembly program. I have instructions for moving, eating, moving and attacking, reproducing, and sleeping. In addition, I have some very basic branches and loops. So based on the bit pattern, the creature has a certain behaviour. Also, changes in the bit-pattern can cause changes in behaviour. They can be subtle, or drastic. At least, that is what I believe. I need to actually implement my idea before I can find out! My God program is essentially an operating system, and the &#8220;creatures&#8221; are tasks. There&#8217;s a little more to all of this, but I can&#8217;t write it all here. If and when I finish the program, I will make a separate page for it and describe it in detail.</p>
<p>I am thinking of calling this program &#8220;Eden&#8221;. Anyway, that&#8217;s all for now!</p>
<br /><a href="http://vivin.net/?p=295#comments" title="Comments on &quot;Intel and Artificial Life&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?295" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=295&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2004/09/17/intel-and-artificial-life/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?295" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?295" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=295&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>Ecological Simulators and Photo Albums</title>
		<link>http://vivin.net/2002/09/27/ecological-simulators-and-photo-albums/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2002/09/27/ecological-simulators-and-photo-albums/#comments</comments>
		<pubDate>Fri, 27 Sep 2002 09:06:29 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[artificial life]]></category>
		<category><![CDATA[artificial life simulator]]></category>
		<category><![CDATA[cse421]]></category>
		<category><![CDATA[ecological simulator]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[my website]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[photo album]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[pictures]]></category>
		<category><![CDATA[simulator]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=85</guid>
		<description><![CDATA[I finished the &#8220;Delete Photos&#8221; page on the Photo Album Tools page&#8230; which of course, none of you can see, since it&#8217;s in the admin section. But anyway&#8230; It took me this long, because I had other stuff to take care of&#8230; namely CSE 421. I only have the &#8220;Update Photos&#8221; tool to finish&#8230; after [...]]]></description>
			<content:encoded><![CDATA[<p>I finished the &#8220;Delete Photos&#8221; page on the Photo Album Tools page&#8230; which of course, none of you can see, since it&#8217;s in the admin section. But anyway&#8230; It took me this long, because I had other stuff to take care of&#8230; namely CSE 421. I only have the &#8220;Update Photos&#8221; tool to finish&#8230; after that, I should start working on the actual photo album display page. In other news, I&#8217;m working on a JavaScript version of my Perl Ecological simulator (the one that ran wild on ASU&#8217;s general server&#8230; ohhh I&#8217;m so proud of myself). Except in this case, it&#8217;s objects that are killing each other&#8230; it should give me a lot more flexibility. My creatures even have randomly generated names like &#8220;zexoyiwub&#8221; and &#8220;xorigewor&#8221;. It&#8217;s going to be fun&#8230; once/if I finish it.</p>
<br /><a href="http://vivin.net/?p=85#comments" title="Comments on &quot;Ecological Simulators and Photo Albums&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?85" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=85&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2002/09/27/ecological-simulators-and-photo-albums/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?85" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?85" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=85&#38;type=feed" medium="image" />
	</item>
	</channel>
</rss>

