<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: RPN Calculator &#8211; Keeping Boredom Away</title>
	<atom:link href="http://shriphani.com/blog/2009/01/14/rpn-calculator/feed/" rel="self" type="application/rss+xml" />
	<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/</link>
	<description>In Pursuit Of Truth and Beauty</description>
	<lastBuildDate>Wed, 08 Sep 2010 16:44:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Shriphani</title>
		<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/comment-page-1/#comment-3719</link>
		<dc:creator>Shriphani</dc:creator>
		<pubDate>Fri, 16 Jan 2009 01:50:34 +0000</pubDate>
		<guid isPermaLink="false">http://shriphani.com/blog/?p=308#comment-3719</guid>
		<description>I&#039;ve disabled automatic smileys. That shouldn&#039;t be a problem anymore.

&lt;strong&gt;Dethe Elza:&lt;/strong&gt;
Thanks a lot for mentioning that. 

&lt;strong&gt;rcriii:&lt;/strong&gt;
That looks cool. Thanks for posting your version.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve disabled automatic smileys. That shouldn&#8217;t be a problem anymore.</p>
<p><strong>Dethe Elza:</strong><br />
Thanks a lot for mentioning that. </p>
<p><strong>rcriii:</strong><br />
That looks cool. Thanks for posting your version.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rcriii</title>
		<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/comment-page-1/#comment-3716</link>
		<dc:creator>rcriii</dc:creator>
		<pubDate>Thu, 15 Jan 2009 20:16:42 +0000</pubDate>
		<guid isPermaLink="false">http://shriphani.com/blog/?p=308#comment-3716</guid>
		<description>May I suggest adding this to __init__:

&lt;pre lang=&quot;python&quot;&gt;
self.operations = {&#039;+&#039;:lambda o1, o2:o1+o2,
                              &#039;-&#039;:lambda o1, o2:o1-o2,
                              &#039;*&#039;:lambda o1, o2:o1*o2,
                              &#039;/&#039;:lambda o1, o2:o1/o2,
                              &#039;^&#039;:lambda o1, o2:o1**o2}

The isOperator becomes:
def isOperator(self, char):
                &quot;&quot;&quot;Checks whether the last item entered in the stack is an operator or not&quot;&quot;&quot;
                if char in self.operations.keys():
                        return True
                else:
                        return False

and Operate() becomes:

def operate(self, operator):
                &quot;&quot;&quot;&quot;Perform the stated operation on the last two elements in the stack&quot;&quot;&quot;
                operand1 = float(self.stack[-1])
                operand2 = float(self.stack[-2])

                self.stack.pop()
                self.stack.pop()

                    self.stack.append(self.operations[operator](operand1, operand2))
&lt;/pre&gt;
And adding operators becomes quite easy.</description>
		<content:encoded><![CDATA[<p>May I suggest adding this to __init__:</p>
<pre lang="python">
self.operations = {'+':lambda o1, o2:o1+o2,
                              '-':lambda o1, o2:o1-o2,
                              '*':lambda o1, o2:o1*o2,
                              '/':lambda o1, o2:o1/o2,
                              '^':lambda o1, o2:o1**o2}

The isOperator becomes:
def isOperator(self, char):
                """Checks whether the last item entered in the stack is an operator or not"""
                if char in self.operations.keys():
                        return True
                else:
                        return False

and Operate() becomes:

def operate(self, operator):
                """"Perform the stated operation on the last two elements in the stack"""
                operand1 = float(self.stack[-1])
                operand2 = float(self.stack[-2])

                self.stack.pop()
                self.stack.pop()

                    self.stack.append(self.operations[operator](operand1, operand2))
</pre>
<p>And adding operators becomes quite easy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dethe Elza</title>
		<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/comment-page-1/#comment-3714</link>
		<dc:creator>Dethe Elza</dc:creator>
		<pubDate>Thu, 15 Jan 2009 17:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://shriphani.com/blog/?p=308#comment-3714</guid>
		<description>If you&#039;re going to have folks talking about code, turning off automatic smiley&#039;s would be a good step.  The second example above should have ended with an eight (8) followed by a closing parenthesis.</description>
		<content:encoded><![CDATA[<p>If you&#8217;re going to have folks talking about code, turning off automatic smiley&#8217;s would be a good step.  The second example above should have ended with an eight (8) followed by a closing parenthesis.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dethe Elza</title>
		<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/comment-page-1/#comment-3713</link>
		<dc:creator>Dethe Elza</dc:creator>
		<pubDate>Thu, 15 Jan 2009 17:09:23 +0000</pubDate>
		<guid isPermaLink="false">http://shriphani.com/blog/?p=308#comment-3713</guid>
		<description>Someone suggested that the leading 0 will produce octal content in Python.  While this used to be true, it has been fixed in more recent versions (I tested in Python 2.5.2).  To interpret a string as an octal value in Python you now are expected to pass the base to int, thus:

&gt;&gt;&gt; int(&#039;012345&#039;)
12345

but

&gt;&gt;&gt; int(&#039;012345&#039;, 8)
5349

&quot;Explicit is better than implicit&quot; strikes again</description>
		<content:encoded><![CDATA[<p>Someone suggested that the leading 0 will produce octal content in Python.  While this used to be true, it has been fixed in more recent versions (I tested in Python 2.5.2).  To interpret a string as an octal value in Python you now are expected to pass the base to int, thus:</p>
<p>&gt;&gt;&gt; int(&#8217;012345&#8242;)<br />
12345</p>
<p>but</p>
<p>&gt;&gt;&gt; int(&#8217;012345&#8242;, 8)<br />
5349</p>
<p>&#8220;Explicit is better than implicit&#8221; strikes again</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shriphani</title>
		<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/comment-page-1/#comment-3712</link>
		<dc:creator>Shriphani</dc:creator>
		<pubDate>Thu, 15 Jan 2009 14:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://shriphani.com/blog/?p=308#comment-3712</guid>
		<description>&lt;strong&gt;Marius:&lt;/strong&gt;
Thanks for your comments. Will keep them in mind.

&lt;strong&gt;Everyone Else&lt;/strong&gt;
Thanks for answering my question.</description>
		<content:encoded><![CDATA[<p><strong>Marius:</strong><br />
Thanks for your comments. Will keep them in mind.</p>
<p><strong>Everyone Else</strong><br />
Thanks for answering my question.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xtian</title>
		<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/comment-page-1/#comment-3709</link>
		<dc:creator>xtian</dc:creator>
		<pubDate>Thu, 15 Jan 2009 13:08:56 +0000</pubDate>
		<guid isPermaLink="false">http://shriphani.com/blog/?p=308#comment-3709</guid>
		<description>Octal octal, octal octal octal. Octal octal octal; octal.

Oc tal octaaaaaaaaaaaallllllll!</description>
		<content:encoded><![CDATA[<p>Octal octal, octal octal octal. Octal octal octal; octal.</p>
<p>Oc tal octaaaaaaaaaaaallllllll!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marius Gedminas</title>
		<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/comment-page-1/#comment-3708</link>
		<dc:creator>Marius Gedminas</dc:creator>
		<pubDate>Thu, 15 Jan 2009 10:13:05 +0000</pubDate>
		<guid isPermaLink="false">http://shriphani.com/blog/?p=308#comment-3708</guid>
		<description>Small clarification: it was supposed to be &quot;PEP 8&quot; (http://www.python.org/dev/peps/pep-0008/) followed by a closing parenthesis, and not a smiley at all.</description>
		<content:encoded><![CDATA[<p>Small clarification: it was supposed to be &#8220;PEP 8&#8243; (<a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">http://www.python.org/dev/peps/pep-0008/</a>) followed by a closing parenthesis, and not a smiley at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marius Gedminas</title>
		<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/comment-page-1/#comment-3707</link>
		<dc:creator>Marius Gedminas</dc:creator>
		<pubDate>Thu, 15 Jan 2009 10:11:33 +0000</pubDate>
		<guid isPermaLink="false">http://shriphani.com/blog/?p=308#comment-3707</guid>
		<description>I won&#039;t mention the word &quot;octal&quot; since nine people before me have already done so. ;-)

A couple of suggestions for the Python code: the de facto standard indentation, also blessed by the official style guide (PEP 8) is 4 spaces per level, not 8.

You can express the operator check more concisely as 
   return char in [&#039;+&#039;, &#039;-&#039;, &#039;*&#039;, &#039;/&#039;]

Also, &#039;char&#039; is not a particularly good name since it may well be a multi-character string containing a floating point number.

list.pop() defaults to popping the last item, so passing -1 is redundant.

You&#039;ve already converted both operands to floats when you extracted them from the stack (personally, I&#039;d convert them when inserting into the stack, but whatever), so there&#039;s no need for a repeated conversion where you&#039;re implementing division.  On the other hand, this may be a place where explicit is better than implicit.

Machine.__init__ ignores the stack argument.  Also beware of using mutable types such as lists for default argument values, you can easily end up sharing objects without intending to do so.

I&#039;d also use &#039;return&#039; in place of &#039;raise SystemExit&#039;.</description>
		<content:encoded><![CDATA[<p>I won&#8217;t mention the word &#8220;octal&#8221; since nine people before me have already done so. ;-)</p>
<p>A couple of suggestions for the Python code: the de facto standard indentation, also blessed by the official style guide (PEP 8) is 4 spaces per level, not 8.</p>
<p>You can express the operator check more concisely as<br />
   return char in ['+', '-', '*', '/']</p>
<p>Also, &#8216;char&#8217; is not a particularly good name since it may well be a multi-character string containing a floating point number.</p>
<p>list.pop() defaults to popping the last item, so passing -1 is redundant.</p>
<p>You&#8217;ve already converted both operands to floats when you extracted them from the stack (personally, I&#8217;d convert them when inserting into the stack, but whatever), so there&#8217;s no need for a repeated conversion where you&#8217;re implementing division.  On the other hand, this may be a place where explicit is better than implicit.</p>
<p>Machine.__init__ ignores the stack argument.  Also beware of using mutable types such as lists for default argument values, you can easily end up sharing objects without intending to do so.</p>
<p>I&#8217;d also use &#8216;return&#8217; in place of &#8216;raise SystemExit&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/comment-page-1/#comment-3704</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Thu, 15 Jan 2009 00:03:43 +0000</pubDate>
		<guid isPermaLink="false">http://shriphani.com/blog/?p=308#comment-3704</guid>
		<description>Oh, I know, Octal! ;-)</description>
		<content:encoded><![CDATA[<p>Oh, I know, Octal! ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: foo</title>
		<link>http://shriphani.com/blog/2009/01/14/rpn-calculator/comment-page-1/#comment-3702</link>
		<dc:creator>foo</dc:creator>
		<pubDate>Wed, 14 Jan 2009 21:39:57 +0000</pubDate>
		<guid isPermaLink="false">http://shriphani.com/blog/?p=308#comment-3702</guid>
		<description>&gt; int a = 012345;

That would be octal. From http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html:

&quot;&quot;&quot;
The prefix 0 indicates octal, whereas 0x indicates hexadecimal.

         ...
         int octVal = 032; 	// The number 26, in octal
&quot;&quot;&quot;</description>
		<content:encoded><![CDATA[<p>&gt; int a = 012345;</p>
<p>That would be octal. From <a href="http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html" rel="nofollow">http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html</a>:</p>
<p>&#8220;&#8221;"<br />
The prefix 0 indicates octal, whereas 0x indicates hexadecimal.</p>
<p>         &#8230;<br />
         int octVal = 032; 	// The number 26, in octal<br />
&#8220;&#8221;"</p>
]]></content:encoded>
	</item>
</channel>
</rss>
