<?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/"
	>

<channel>
	<title>Jason Rowe &#187; General Programming</title>
	<atom:link href="http://jasonrowe.com/category/general-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://jasonrowe.com</link>
	<description>enjoying the web</description>
	<lastBuildDate>Tue, 03 Jan 2012 02:03:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Getting back into JavaScript</title>
		<link>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-back-into-javascript</link>
		<comments>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 04:17:32 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1498</guid>
		<description><![CDATA[The last time I did any serious JavaScript was around the time Sizzle was added to JQuery, Google Chrome was brand new, and MarketWatch.com started using canvas charts. Note: Here is a quick overview of JavaScript that is as short&#8230;]]></description>
			<content:encoded><![CDATA[<p>The last time I did any serious JavaScript was around the time Sizzle was added to JQuery, Google Chrome was brand new, and MarketWatch.com started using canvas charts.</p> 

<p><strong>Note:</strong> Here is a quick <a href="http://www.2ality.com/2011/10/javascript-overview.html">overview of JavaScript</a> that is as short as possible, but explains every major feature. I would also recommend following the <a href="http://www.2ality.com/">2ality</a> website</p>

<p>Today JavaScript projects have the complexity, size, and structure of projects written in languages like C# and Java. Thankfully, the developer tools for debugging and logging are solid across browsers. *<i>Opera is still a little funky about logging using &#8220;opera.postError.apply(opera, arguments);&#8221;</i>. Looking particularly good, <a href="http://code.google.com/chrome/devtools/">Google&#8217;s version of the webkit dev tools</a> and some API&#8217;s they have in <a href="http://code.google.com/chrome/extensions/dev/experimental.devtools.html">beta</a>. I’ve started to use <a href="http://docs.jquery.com/QUnit">quint</a> for unit testing. I’ve also been looking leveraging these frameworks: <a href="http://documentcloud.github.com/underscore/">underscore.js</a>, <a href="http://jashkenas.github.com/coffee-script/">coffee script</a>, <a href="http://raphaeljs.com/">raphaeljs</a>, and <a href="http://code.google.com/closure/compiler/">closure compiler</a>.</p> <p>It’s amazing how much has changed. Now <a href="https://developer.mozilla.org/en/JavaScript/Reference">examples of good JavaScript</a> are much easier to find. Hell, here is a step by step walkthrough of how to <a href="http://dailyjs.com/tags.html#lmaf">build your very own JavaScript framework</a>.</p> 

<p>So to get some practice I went and found some JS that needed cleanup. I wanted to focus on structure and namespaces and this <a href="http://www.elated.com/res/File/articles/development/javascript/snazzy-animated-pie-chart-html5-jquery/">script</a> needed some love. View source on that page and you will notice global variables and one big pile of code.</p> <p>The first thing I did was break up the logic into separate functional script files that will later be compiled and minified into one. You can see the python script I use to minify <a href="https://raw.github.com/JasonRowe/SimpleHTML5.Charts/master/build.py">here</a>.</p> 

<ol> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/animation.js">animation.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/builder.js">builder.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/core.js">core.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/pie.js">pie.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/rendering.js">rendering.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/styles.js">styles.js</a></li>
</ol> 

<p>I then added a <a href="https://github.com/JasonRowe/SimpleHTML5.Charts/tree/master/test">test folder</a> and setup the same file names but which had test cases for each script. Then an index.html file to display the test groups or “modules” as they are called in QUnit. Here is an example of a test that always passes</p> 

<pre class="brush: js; ">

module(&quot;sample test&quot;);

test(&quot;a sample qunit test&quot;, function () {
    ok(true, &quot;always fine&quot;);
});


</pre>  

<p>The next thing I worked on was getting a namespace around the code. I went with the following which seems to work for my needs.</p> 

<pre class="brush: js; ">

var MYAPP = MYAPP || {};

MYAPP.namespace = function (ns_string) { var parts = ns_string.split(&#039;.&#039;), parent = MYAPP, i; // strip redundant leading global 

if (parts[0] === &quot;MYAPP&quot;) { parts = parts.slice(1); } for (i = 0; i &lt; parts.length; i += 1) { // create a property if it doesn&#039;t exist 

if (typeof parent[parts[i]] === &quot;undefined&quot;) { parent[parts[i]] = {}; 

} parent = parent[parts[i]]; } return parent; }; 


</pre>  

<p>Stefanov, Stoyan (2010). JavaScript Patterns (pp. 89-90). OReilly Media &#8211; A. Kindle Edition. </p>

<p>So after refactoring, I’ve got the pie chart setup code to the following.</p>

<pre class="brush: js; ">

var pieElm = document.getElementById(&#039;pieChart&#039;);
var pieData = $(&#039;#chartData td&#039;);

var pieChart = new SimpleHtml5.Core.Pie(pieElm, pieData);

$(&#039;#pieChart&#039;).click (pieChart, SimpleHtml5.Pie.Animation.HandleChartClick);

</pre>

<p>To customize the style I allow passing in a custom style object to override the defaults.</p>

<pre class="brush: js; ">


var customStyles = {
    chartSizePercent: 49,
    maxPullOutDistance: 10,
    pullOutFrameStep: 4,
    pullOutFrameInterval: 40,
    pullOutLabelPadding: 42
};

var pieElm = document.getElementById(&#039;pieChart&#039;);
var pieData = $(&#039;#chartData td&#039;);
var pieChart = new SimpleHtml5.Core.Pie(pieElm, pieData, customStyles);
$(&#039;#pieChart&#039;).click (pieChart, SimpleHtml5.Pie.Animation.HandleChartClick);

</pre>

<p>
If you are curious about how the other parts of the chart were organized you can see the source code on <a href="https://github.com/JasonRowe/SimpleHTML5.Charts">github</a>.
</p>

<p>

<blockquote>I can also be found on Google+

<a title="Jason Rowe is on Google+" rel="author" href="http://profiles.google.com/jasonrowe?rel=author" alt="Google+" title="Google+">Jason Rowe</a> and twitter <a title="Jason Rowe is on twitter" rel="author" href="http://twitter.com/jsonrow?rel=author" alt="twitter" title="twitter">@jsonrow</a>
</blockquote>


</p>

]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blogging with Google App Engine</title>
		<link>http://jasonrowe.com/2010/10/17/blogging-with-google-app-engine/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=blogging-with-google-app-engine</link>
		<comments>http://jasonrowe.com/2010/10/17/blogging-with-google-app-engine/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 16:33:23 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[GAE]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1400</guid>
		<description><![CDATA[&#160; A recent post and talk on twitter about host providers got me interested in building a blog using Google App Engine (GAE). It&#8217;s free to use and would eliminate having to pay for a hosting provider for a small&#8230;]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p> <p>A recent <a href="http://www.murphybytes.com/2010/09/29/gae-is-better-than-ec2/">post</a> and talk on twitter about host providers got me interested in building a blog using Google App Engine (GAE). It&#8217;s free to use and would eliminate having to pay for a hosting provider for a small site. My blog turned out like this <a href="http://jsoncharts.appspot.com/">jsoncharts</a>. I&#8217;m pretty happy with it so far.

<p>I got started with Python and GAE by reading the documentation and using the examples on the <a href="http://code.google.com/appengine/docs/python/gettingstarted/introduction.html">Google App Engine site</a>. Then I used this <a href="http://brizzled.clapper.org/id/77/">article</a> and framework for the base of my blog. The major changes I made were adding commenting and friendly URL’s. I can have URL’s like this (<a title="http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael" href="http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael">http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael</a>) and comments on the articles (<a title="http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael#respond" href="http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael#respond">http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael#respond</a>). </p> <p>Adding friendly URL’s was easy enough. Following <a href="http://bret.appspot.com/entry/experimenting-google-app-engine">Bret Taylor’s example</a> here is what my WSGIApplication instance looks like.</p> 

<pre class="brush: python; ">
 
application = webapp.WSGIApplication(
    [(&#039;/&#039;, FrontPageHandler),
     (&#039;/tag/([^/]+)/*$&#039;, ArticlesByTagHandler),
     (&#039;/date/(\d\d\d\d)-(\d\d)/?$&#039;, ArticlesForMonthHandler),
     (&#039;/&#039;+ defs.ARTICLE_URL_PATH +&#039;/(\d+)/?$&#039;, SingleArticleHandler),
     (&#039;/&#039;+ defs.ARTICLE_URL_PATH +&#039;/([^/]+)&#039;, SingleArticleHandlerBySlug),
     (&#039;/archive/?$&#039;, ArchivePageHandler),
     (&#039;/rss2/?$&#039;, RSSFeedHandler),
     (&#039;/.*$&#039;, NotFoundPageHandler),
     ], 

</pre>

<p>The following line routes incoming request to a class handler named “SingleArticleHandlerBySlug”.</p> 

<pre class="brush: python; ">
 
(&#039;/&#039;+ defs.ARTICLE_URL_PATH +&#039;/([^/]+)&#039;, SingleArticleHandlerBySlug),

</pre>

<p>The handler looks like this:</p> 

<pre class="brush: python; ">
 
class SingleArticleHandlerBySlug(AbstractPageHandler):
    &quot;&quot;&quot;
    Handles requests to display a single article, given its unique ID.
    Handles nonexistent IDs.
    &quot;&quot;&quot;
    def get(self, slug):
        article = Article.get_for_slug(slug)
        comments = None
        if article:
            comments = Comment.get_all_by_articleId(article.id)
            template = &#039;show-single-article.html&#039;
            articles = [article]
            more = None
        else:
            template = &#039;not-found.html&#039;
            articles = [] 

        self.response.out.write(self.render_articles(articles=articles,
                                                     request=self.request,
                                                     recent=self.get_recent(),
                                                     template_name=template,
                                                     comments=comments)) 

</pre>

<p>To add the commenting I had to create a new model class for storage. This was very simple.</p> 

<pre class="brush: python; ">
 
class Comment(db.Model): 

    name = db.TextProperty()
    email = db.TextProperty()
    website = db.TextProperty()
    body = db.TextProperty()
    commented_when = db.DateTimeProperty(auto_now_add=True)
    id = db.IntegerProperty()
    articleId = db.IntegerProperty()
    gravatar_url = db.TextProperty() 

</pre>

<p>Then I added a few functions for finding and deleting and then added them in. I can’t remember ever doing something with storage this fast. I don&#8217;t miss SQL at all. GAE really hides all the storage implementation details for you. Here is an example of the functions used to access the data store.</p> 

<pre class="brush: python; ">
 
@classmethod
def get_all(cls):
    q = db.Query(Comment)
    q.order(&#039;-commented_when&#039;)
    return q.fetch(FETCH_THEM_ALL)
@classmethod
def get_all_by_articleId(cls, articleId):
    q = db.Query(Comment)
    q.filter(&#039;articleId = &#039;, articleId)
    q.order(&#039;-commented_when&#039;)
    return q.fetch(FETCH_THEM_ALL) 

</pre>

<p>That’s all it takes and you are ready to go.</p> <p>Overall I was very impressed with the experience. In the future I&#8217;ll probably look into using Django&#8217;s form validation framework for comments and figure out how backups would work.</p>

Post Related Links:
<ul>
<li><a href="https://github.com/JasonRowe/picoblog">JsonChart Fork on GitHub</a></li>
<li><a href="https://github.com/bmc/picoblog">PicoBlog on GitHub</a></li>
<li><a href="http://brizzled.clapper.org/id/77/">Writing Blogging Software for Google App Engine</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/10/17/blogging-with-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shiny New Toys, Visitor Pattern, and Real World Functional Programming</title>
		<link>http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=shiny-new-toys-visitor-pattern-and-real-world-functional-programming</link>
		<comments>http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 04:21:41 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Commentary]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1333</guid>
		<description><![CDATA[&#160; Last week in the office I thought to my self, “Holiday weekend coming! I’ll have time to play with WP7 or maybe I’ll play with HTML5”. Then I saw this tweet on twitter. We as developers spend too much&#8230;]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p> <p>Last week in the office I thought to my self, “Holiday weekend coming! I’ll have time to play with WP7 or maybe I’ll play with HTML5”. Then I saw this <a href="http://twitter.com/jeremydmiller/status/22798775378">tweet</a> on twitter.</p> <blockquote> <p>We as developers spend too much time playing with baubles and shiny new tools and not enough time on core skills and fundamentals</p></blockquote> <p>I thought well, instead of using some free time this holiday weekend to build something why not do a little research. I happened to have a problem at work which someone suggested using the Visitor Pattern. So I spent some time looking over a few resources and <a href="http://en.wikipedia.org/wiki/Visitor_pattern">Wikipedia</a> has a great explanation. I won’t try to repeat that. One area I was stuck on though was the concept of double dispatch. I found this <a href="http://bit.ly/bZRM74">example</a> on <a href="http://stackoverflow.com/questions/479923/is-c-a-single-dispatch-or-multiple-dispatch-language">StackOverflow.com</a> which solidified the concept. For some reason <a href="http://bit.ly/bZRM74">learning by spaceship and rebel alliance</a> works for me.</p> <p>So now that I had a good understand all I needed to was implement it right? I thought about it and figured that could wait. Now is an opportunity to work on my fundamentals. The Wikipedia article mentioned Common Lisp and how the Visitor Pattern simplified when using dynamic languages. This got me to thinking what would this look like in F# or a functional language? </p> <p>While looking into functional languages I came across this Stack Overflow question “<a href="http://stackoverflow.com/questions/3642328/i-am-a-c-developer-should-i-start-looking-more-on-f-closed">I am a C# developer, Should I start looking more on F# [closed]</a>”.&nbsp; Jon Skeet’s answer influenced me and I figured I would pick up a book <a href="http://manning.com/petricek">Real World Functional Programming</a>. It fits into the category of fundamentals because it’s using C# and F# to teach functional programming. Which I haven’t used in many years.</p> <p>So I start reading with the goal in mind that I would make a quick example of the visitor pattern in F#. Don’t think I am a super geek (not that you would be confused because of my skills). I did take time to drink a few of <a href="http://www.surlybrewing.com/beer/year-round-beers.html">these</a> and go to the Crowded House concert this weekend. By the fourth chapter or so things started to sink in with F# and functional programming. </p> <p>If I were using a declarative functional style of programming, I wouldn’t even need the visitor pattern at all!&nbsp; I don’t have objects that would need to be separated from the algorithm. I would only have types and could use pattern matching and discriminated unions to perform my algorithm. The visitor pattern is needed in my current project because I’m using an implicit OO coding approach.</p> <p>It was really shocking to me that this wasn’t obvious right away. I’ve been doing OO for so long now I’ve completely become accustomed to dealing with objects and state. A programming world without objects had completely slipped from my mind. Glad I took the time to get started on this book as it’s already giving me new ideas and techniques I can use in my daily C# and OO programming. Now to start working on some of the other <a href="http://www.indiangeek.net/wp-content/uploads/Programmer%20competency%20matrix.htm">programmer competencies</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turing&#8217;s Lambda Notation</title>
		<link>http://jasonrowe.com/2009/09/05/turings-lambda-notation/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=turings-lambda-notation</link>
		<comments>http://jasonrowe.com/2009/09/05/turings-lambda-notation/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 06:50:26 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Commentary]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[Lambda]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=642</guid>
		<description><![CDATA[I&#8217;m still working through Turing&#8217;s paper on Computability and the Turing Machine.  I am at the end and reading the appendix on Alonzo Church&#8217;s equivalent approach using Lambda Calculus.   His work is so familiar to most programmers since we&#8230;]]></description>
			<content:encoded><![CDATA[I&#8217;m still working through Turing&#8217;s paper on Computability and the Turing Machine.  I am at the end and reading the appendix on Alonzo Church&#8217;s equivalent approach using Lambda Calculus.   His work is so familiar to most programmers since we use the concepts in C, C++, Java, and C#.   I decided to use C# Lambda syntax to get familiar before reading through the rest of the paper.

<a rel="attachment wp-att-658" href="http://jasonrowe.com/2009/09/05/turings-lambda-notation/lambda_math_syntax-2/"><img class="alignnone size-full wp-image-658" title="lambda_math_syntax" src="http://jasonrowe.com/wp-content/uploads/2009/09/lambda_math_syntax.PNG" alt="lambda_math_syntax" width="537" height="136" /></a>

I started simply and considered how I could make the following expression be represented by M.

<strong>Math.Pow(x, 2.0) + 5 * x + 7</strong>

Most commonly we see it in this form when programming.

<pre class="brush: c#; ">


static double F(double x)
{

return Math.Pow(x, 2.0) + 5 * x + 7;

}


</pre>

So convert it to a lambda expression.

<pre class="brush: c#; ">


OneV firstExp = x =&gt; Math.Pow(x, 2.0) + 5 * x + 7;


</pre>

where OneV is defined as (not suprisingly)

<pre class="brush: c#; ">


delegate double OneV(double x);


</pre>

In C# the two variable syntax could be something like this:

<pre class="brush: c#; ">


TwoV Exp = (x, y) =&gt; Math.Pow(y, 2.0) + 5 * y + 18 * x + 2 * x * y + 7;


</pre>

So thats how I got my head around the very basic syntax.]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2009/09/05/turings-lambda-notation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intro to Propositional Logic Using C#</title>
		<link>http://jasonrowe.com/2009/08/28/intro-to-propositional-logic-using-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=intro-to-propositional-logic-using-c</link>
		<comments>http://jasonrowe.com/2009/08/28/intro-to-propositional-logic-using-c/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 03:18:20 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Propositional Logic]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=628</guid>
		<description><![CDATA[I&#8217;ve been reading about propositional (or sentential) logic in the book &#8220;The Annotated Turing&#8221;. I put together a quick console app to write out truth tables. It helped me get the hang of the mathematical notation &#8220;v&#8221;, &#8220;&#038;&#8221;, and &#8220;->&#8221;.&#8230;]]></description>
			<content:encoded><![CDATA[I&#8217;ve been reading about propositional (or sentential) logic in the book &#8220;The Annotated Turing&#8221;.  I put together a quick console app to write out truth tables. It helped me get the hang of the mathematical notation &#8220;v&#8221;, &#8220;&#038;&#8221;, and &#8220;->&#8221;. In C# those would be ||, &#038;&#038;, and !x || y respectively. I hope someone else finds it useful.

<pre class="brush: c#; ">

using System;
using System.Collections.Generic;

namespace PropositionalLogic
{
    public class Program
    {
        public class truthvalue
        {
            public bool X { get; set; }
            public bool Y { get; set; }
        }

        public static bool XorY(bool x, bool y)
        {
            return (x || y);
        }

        public static bool XandY(bool x, bool y)
        {
            return (x &amp;&amp; y);
        }

        public static bool Exclusive(bool x, bool y)
        {
            return (x &amp;&amp; y) &amp;&amp; !(x &amp;&amp; y);// always false
        }

        public static bool Tautoloty(bool x, bool y)
        {
            return x || y || (!x &amp;&amp; !y);// always true
        }

        public static bool Contradition(bool x, bool y)
        {
            return x || (y &amp;&amp; !y);
        }

        public static bool MaterialImplication(bool x, bool y)
        {
            return !x || y; //this can also be expressed as the following conjunction !(x &amp;&amp; !y);
        }

        public static bool BiConditional(bool x, bool y)
        {
            return MaterialImplication(x, y) &amp;&amp; MaterialImplication(y, x); //&quot;if and only if&quot;
        }

        static void Main(string[] args)
        {
            var truthTable = new List&lt;truthvalue&gt;
                                 {
                                     new truthvalue() {X = false, Y = false},
                                     new truthvalue() {X = false, Y = true},
                                     new truthvalue() {X = true, Y = false},
                                     new truthvalue() {X = true, Y = true}
                                 };

            var sentences = new Dictionary&lt;string , Func&lt;bool, bool, bool&gt;&gt;
                                {
                                    {&quot;X v Y&quot;, XorY},
                                    {&quot;X &amp; Y&quot;, XandY},
                                    {&quot;(x v y)&amp; -(x &amp; y)&quot;, Exclusive},
                                    {&quot;x v y v (-x &amp; -y)&quot;, Tautoloty},
                                    {&quot;x -&gt; y&quot;, MaterialImplication},
                                    {&quot;x ~ y&quot;, BiConditional}
                                };

            CalculateTruthTable(truthTable, sentences);

            Console.ReadLine();
        }

        private static void CalculateTruthTable(IEnumerable&lt;truthvalue&gt; truthTable, Dictionary&lt;string , Func&lt;bool, bool, bool&gt;&gt; sentences)
        {
            foreach (var sentence in sentences)
            {
                Console.WriteLine(&quot;&quot;);
                Console.WriteLine(&quot;|X      |Y      |{0}  |&quot;, sentence.Key);

                foreach (var value in truthTable)
                {
                    var x = value.X;
                    var y = value.Y;

                    var result = sentence.Value(x, y);

                    Console.WriteLine(&quot;|{0}  |{1}  |{2}  |&quot;, PrettyPrint(x), PrettyPrint(y), PrettyPrint(result));
                }
            }
        }

        private static string PrettyPrint(bool input)
        {
            return input ? input + &quot; &quot; : input.ToString();
        }
    }
}

</pre>
</string></truthvalue></string></truthvalue>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2009/08/28/intro-to-propositional-logic-using-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

