<?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: Java.beyond</title>
	<atom:link href="http://www.programmersparadox.com/2008/09/14/javabeyond/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.programmersparadox.com/2008/09/14/javabeyond/</link>
	<description>Is anything I write real?</description>
	<lastBuildDate>Thu, 04 Mar 2010 17:17:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ulf Wiger</title>
		<link>http://www.programmersparadox.com/2008/09/14/javabeyond/comment-page-1/#comment-1792</link>
		<dc:creator>Ulf Wiger</dc:creator>
		<pubDate>Tue, 16 Sep 2008 16:22:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.programmersparadox.com/?p=309#comment-1792</guid>
		<description>Unfortunately, the test code is so verbose that one cannot bare to look at it (no offense, guys ;-)

Here&#039;s a version together with a unit test using QuickCheck.
It tests both valid and some invalid inputs
(not sure how to get the formatting right, though):


-module(grades).
-export([grades/1, test/0]).
-include_lib(&quot;eqc/include/eqc.hrl&quot;).

-define(VALID_GRADES, &quot;abcdfABCDF&quot;).

grades(N) when is_integer(N), N &gt; 100 -&gt; invalid;
grades(N) when N == &quot;A&quot;; N == &quot;a&quot;; is_integer(N), N &gt;= 90 -&gt; &quot;A&quot;;
grades(N) when N == &quot;B&quot;; N == &quot;b&quot;; is_integer(N), N &gt;= 80 -&gt; &quot;B&quot;;
grades(N) when N == &quot;C&quot;; N == &quot;c&quot;; is_integer(N), N &gt;= 70 -&gt; &quot;C&quot;;
grades(N) when N == &quot;D&quot;; N == &quot;d&quot;; is_integer(N), N &gt;= 60 -&gt; &quot;D&quot;;
grades(N) when N == &quot;F&quot;; N == &quot;f&quot;; is_integer(N), N &gt;= 0 -&gt; &quot;F&quot;;
grades(_) -&gt; invalid.

test() -&gt;
    ?FORALL(
       V, oneof([valid,invalid]),
       ?LET(R, result(V),
            expected(V, catch grades(R), R))).

result(valid) -&gt;
    oneof([choose(0,100),
	   [oneof(?VALID_GRADES)]  % string of length 1
	  ]);
result(invalid) -&gt;
    oneof([?LET(N, nat(), -(1+N)),
	   ?LET(N, nat(), N + 101),
	   [?SUCHTHAT(C,choose(0,255),
		      not(lists:member(C,?VALID_GRADES)))] % string
	  ]).

expected(valid,invalid,_) -&gt; false;
expected(invalid,invalid,_) -&gt; true;
expected(valid,G,R) when is_integer(R) -&gt;
    {Min,Max} = interval(G),
    R &gt;= Min andalso R =&lt; Max;
expected(valid,G,R) -&gt;
    string:to_upper(R) == G.

interval(&quot;A&quot;) -&gt; {90,100};
interval(&quot;B&quot;) -&gt; {80,89};
interval(&quot;C&quot;) -&gt; {70,79};
interval(&quot;D&quot;) -&gt; {60,69};
interval(&quot;F&quot;) -&gt; {0,59}.
</description>
		<content:encoded><![CDATA[<p>Unfortunately, the test code is so verbose that one cannot bare to look at it (no offense, guys <img src='http://www.programmersparadox.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Here&#8217;s a version together with a unit test using QuickCheck.<br />
It tests both valid and some invalid inputs<br />
(not sure how to get the formatting right, though):</p>
<p>-module(grades).<br />
-export([grades/1, test/0]).<br />
-include_lib(&#8220;eqc/include/eqc.hrl&#8221;).</p>
<p>-define(VALID_GRADES, &#8220;abcdfABCDF&#8221;).</p>
<p>grades(N) when is_integer(N), N &gt; 100 -&gt; invalid;<br />
grades(N) when N == &#8220;A&#8221;; N == &#8220;a&#8221;; is_integer(N), N &gt;= 90 -&gt; &#8220;A&#8221;;<br />
grades(N) when N == &#8220;B&#8221;; N == &#8220;b&#8221;; is_integer(N), N &gt;= 80 -&gt; &#8220;B&#8221;;<br />
grades(N) when N == &#8220;C&#8221;; N == &#8220;c&#8221;; is_integer(N), N &gt;= 70 -&gt; &#8220;C&#8221;;<br />
grades(N) when N == &#8220;D&#8221;; N == &#8220;d&#8221;; is_integer(N), N &gt;= 60 -&gt; &#8220;D&#8221;;<br />
grades(N) when N == &#8220;F&#8221;; N == &#8220;f&#8221;; is_integer(N), N &gt;= 0 -&gt; &#8220;F&#8221;;<br />
grades(_) -&gt; invalid.</p>
<p>test() -&gt;<br />
    ?FORALL(<br />
       V, oneof([valid,invalid]),<br />
       ?LET(R, result(V),<br />
            expected(V, catch grades(R), R))).</p>
<p>result(valid) -&gt;<br />
    oneof([choose(0,100),<br />
	   [oneof(?VALID_GRADES)]  % string of length 1<br />
	  ]);<br />
result(invalid) -&gt;<br />
    oneof([?LET(N, nat(), -(1+N)),<br />
	   ?LET(N, nat(), N + 101),<br />
	   [?SUCHTHAT(C,choose(0,255),<br />
		      not(lists:member(C,?VALID_GRADES)))] % string<br />
	  ]).</p>
<p>expected(valid,invalid,_) -&gt; false;<br />
expected(invalid,invalid,_) -&gt; true;<br />
expected(valid,G,R) when is_integer(R) -&gt;<br />
    {Min,Max} = interval(G),<br />
    R &gt;= Min andalso R =&lt; Max;<br />
expected(valid,G,R) -&gt;<br />
    string:to_upper(R) == G.</p>
<p>interval(&#8220;A&#8221;) -&gt; {90,100};<br />
interval(&#8220;B&#8221;) -&gt; {80,89};<br />
interval(&#8220;C&#8221;) -&gt; {70,79};<br />
interval(&#8220;D&#8221;) -&gt; {60,69};<br />
interval(&#8220;F&#8221;) -&gt; {0,59}.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.programmersparadox.com/2008/09/14/javabeyond/comment-page-1/#comment-1791</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Tue, 16 Sep 2008 13:51:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.programmersparadox.com/?p=309#comment-1791</guid>
		<description>@Kevin, @Steve,

To defend Kevin, in my implementation I didn&#039;t follow Stuart&#039;s code exactly, and opted to allow grades over 100 and I also didn&#039;t note the restriction in my description of the problem.  What of the case where extra credit is awarded, so the grade is over 100?

So based on the acceptance criteria, this either is, or is not a bug.

Therefore, I think both implementations are equally valid.

I do appreciate seeing the test code in Erlang.  It is a topic that I think is not addressed often enough, how to apply TDD to Erlang.</description>
		<content:encoded><![CDATA[<p>@Kevin, @Steve,</p>
<p>To defend Kevin, in my implementation I didn&#8217;t follow Stuart&#8217;s code exactly, and opted to allow grades over 100 and I also didn&#8217;t note the restriction in my description of the problem.  What of the case where extra credit is awarded, so the grade is over 100?</p>
<p>So based on the acceptance criteria, this either is, or is not a bug.</p>
<p>Therefore, I think both implementations are equally valid.</p>
<p>I do appreciate seeing the test code in Erlang.  It is a topic that I think is not addressed often enough, how to apply TDD to Erlang.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DSmith</title>
		<link>http://www.programmersparadox.com/2008/09/14/javabeyond/comment-page-1/#comment-1790</link>
		<dc:creator>DSmith</dc:creator>
		<pubDate>Tue, 16 Sep 2008 01:18:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.programmersparadox.com/?p=309#comment-1790</guid>
		<description>A slight variation on a previous post...
&lt;code&gt;
-module(grades).
-export([grade/1]).

grade(N) when is_integer(N), N &gt;= 90 -&gt; &quot;A&quot;;
grade(N) when is_integer(N), N &gt;= 80 -&gt; &quot;B&quot;;
grade(N) when is_integer(N), N &gt;= 70 -&gt; &quot;C&quot;;
grade(N) when is_integer(N), N &gt;= 60 -&gt; &quot;D&quot;;
grade(N) when is_integer(N), N &gt;=  0 -&gt; &quot;F&quot;;
grade([G]) when G &gt;= $a, G = [G-32];
grade([G]) when G &gt;= $A, G = [G];
grade(T) -&gt; throw({invalid_grade, T}).
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>A slight variation on a previous post&#8230;<br />
<code><br />
-module(grades).<br />
-export([grade/1]).</p>
<p>grade(N) when is_integer(N), N &gt;= 90 -&gt; "A";<br />
grade(N) when is_integer(N), N &gt;= 80 -&gt; "B";<br />
grade(N) when is_integer(N), N &gt;= 70 -&gt; "C";<br />
grade(N) when is_integer(N), N &gt;= 60 -&gt; "D";<br />
grade(N) when is_integer(N), N &gt;=  0 -&gt; "F";<br />
grade([G]) when G &gt;= $a, G = [G-32];<br />
grade([G]) when G &gt;= $A, G = [G];<br />
grade(T) -&gt; throw({invalid_grade, T}).<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Smith</title>
		<link>http://www.programmersparadox.com/2008/09/14/javabeyond/comment-page-1/#comment-1789</link>
		<dc:creator>Kevin Smith</dc:creator>
		<pubDate>Tue, 16 Sep 2008 00:06:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.programmersparadox.com/?p=309#comment-1789</guid>
		<description>@Steve - You sir are correct. I should&#039;ve read the problem more closely. I totally missed that. Ah well, I still think the code&#039;s not too bad for only spending a few minutes on it.</description>
		<content:encoded><![CDATA[<p>@Steve &#8211; You sir are correct. I should&#8217;ve read the problem more closely. I totally missed that. Ah well, I still think the code&#8217;s not too bad for only spending a few minutes on it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Vinoski</title>
		<link>http://www.programmersparadox.com/2008/09/14/javabeyond/comment-page-1/#comment-1788</link>
		<dc:creator>Steve Vinoski</dc:creator>
		<pubDate>Mon, 15 Sep 2008 20:08:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.programmersparadox.com/?p=309#comment-1788</guid>
		<description>@Mitchell: unfortunately the presence of the test code in the examples above is not enough to prevent bugs. What happens if you pass 101, for example? The originals in the other languages on Stuart&#039;s page would call that an error. My code gets that case right.

If it&#039;s test code you want, here&#039;s my version with the tests attached:

&lt;code&gt;-module(grades).
-export([letter_grade/1, test/0]).

letter_grade(N)
&#160;when is_integer(N), N &gt;= 0, N =&lt; 100 -&gt;
&#160;&#160;L = [&quot;F&quot;, &quot;F&quot;, &quot;F&quot;, &quot;F&quot;, &quot;F&quot;, &quot;F&quot;, &quot;D&quot;,
&#160;&#160;&#160;&quot;C&quot;, &quot;B&quot;, &quot;A&quot;, &quot;A&quot;],
&#160;&#160;lists:nth(trunc(N/10)+1, L);
letter_grade([G&#124;_]=L)
&#160;when length(L) == 1, G &gt;= $A, G =&lt; $F, G =/= $E -&gt;
&#160;&#160;L;
letter_grade([G&#124;_]=L)
&#160;when length(L) == 1, G &gt;= $a, G =&lt; $f, G =/= $e -&gt;
&#160;&#160;string:to_upper(L);
letter_grade(_) -&gt;
&#160;&#160;throw(invalid_grade).

test() -&gt;
&#160;&#160;ok = check_grade(&quot;A&quot;, 90, 100),
&#160;&#160;ok = check_grade(&quot;B&quot;, 80, 89),
&#160;&#160;ok = check_grade(&quot;C&quot;, 70, 79),
&#160;&#160;ok = check_grade(&quot;D&quot;, 60, 69),
&#160;&#160;ok = check_grade(&quot;F&quot;, 0, 59),
&#160;&#160;ok = try letter_grade(101)
&#160;&#160;&#160;catch throw:invalid_grade -&gt; ok;
&#160;&#160;&#160;&#160;_:_ -&gt; fail
&#160;&#160;&#160;end,
&#160;&#160;ok = try letter_grade(-1)
&#160;&#160;&#160;catch throw:invalid_grade -&gt; ok;
&#160;&#160;&#160;&#160;_:_ -&gt; fail
&#160;&#160;&#160;end,
&#160;&#160;ok = try letter_grade(&quot;E&quot;)
&#160;&#160;&#160;catch throw:invalid_grade -&gt; ok;
&#160;&#160;&#160;&#160; _:_ -&gt; fail
&#160;&#160;&#160;end,
&#160;&#160;ok = try letter_grade(&quot;Aa&quot;)
&#160;&#160;&#160;catch throw:invalid_grade -&gt; ok;
&#160;&#160;&#160;&#160; _:_ -&gt; fail
&#160;&#160;&#160;end,
&#160;&#160;ok = try letter_grade(a)
&#160;&#160;&#160;catch throw:invalid_grade -&gt; ok;
&#160;&#160;&#160;&#160;_:_ -&gt; fail
&#160;&#160;&#160;end.

check_grade(Grade, Start, End) -&gt;
&#160;&#160;lists:map(fun(G) -&gt; Grade = letter_grade(G) end,
&#160;&#160;&#160;lists:seq(Start, End)),
&#160;&#160;ok.&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>@Mitchell: unfortunately the presence of the test code in the examples above is not enough to prevent bugs. What happens if you pass 101, for example? The originals in the other languages on Stuart&#8217;s page would call that an error. My code gets that case right.</p>
<p>If it&#8217;s test code you want, here&#8217;s my version with the tests attached:</p>
<p><code>-module(grades).<br />
-export([letter_grade/1, test/0]).</p>
<p>letter_grade(N)<br />
&nbsp;when is_integer(N), N &gt;= 0, N =&lt; 100 -&gt;<br />
&nbsp;&nbsp;L = ["F", "F", "F", "F", "F", "F", "D",<br />
&nbsp;&nbsp;&nbsp;"C", "B", "A", "A"],<br />
&nbsp;&nbsp;lists:nth(trunc(N/10)+1, L);<br />
letter_grade([G|_]=L)<br />
&nbsp;when length(L) == 1, G &gt;= $A, G =&lt; $F, G =/= $E -&gt;<br />
&nbsp;&nbsp;L;<br />
letter_grade([G|_]=L)<br />
&nbsp;when length(L) == 1, G &gt;= $a, G =&lt; $f, G =/= $e -&gt;<br />
&nbsp;&nbsp;string:to_upper(L);<br />
letter_grade(_) -&gt;<br />
&nbsp;&nbsp;throw(invalid_grade).</p>
<p>test() -&gt;<br />
&nbsp;&nbsp;ok = check_grade("A", 90, 100),<br />
&nbsp;&nbsp;ok = check_grade("B", 80, 89),<br />
&nbsp;&nbsp;ok = check_grade("C", 70, 79),<br />
&nbsp;&nbsp;ok = check_grade("D", 60, 69),<br />
&nbsp;&nbsp;ok = check_grade("F", 0, 59),<br />
&nbsp;&nbsp;ok = try letter_grade(101)<br />
&nbsp;&nbsp;&nbsp;catch throw:invalid_grade -&gt; ok;<br />
&nbsp;&nbsp;&nbsp;&nbsp;_:_ -&gt; fail<br />
&nbsp;&nbsp;&nbsp;end,<br />
&nbsp;&nbsp;ok = try letter_grade(-1)<br />
&nbsp;&nbsp;&nbsp;catch throw:invalid_grade -&gt; ok;<br />
&nbsp;&nbsp;&nbsp;&nbsp;_:_ -&gt; fail<br />
&nbsp;&nbsp;&nbsp;end,<br />
&nbsp;&nbsp;ok = try letter_grade("E")<br />
&nbsp;&nbsp;&nbsp;catch throw:invalid_grade -&gt; ok;<br />
&nbsp;&nbsp;&nbsp;&nbsp; _:_ -&gt; fail<br />
&nbsp;&nbsp;&nbsp;end,<br />
&nbsp;&nbsp;ok = try letter_grade("Aa")<br />
&nbsp;&nbsp;&nbsp;catch throw:invalid_grade -&gt; ok;<br />
&nbsp;&nbsp;&nbsp;&nbsp; _:_ -&gt; fail<br />
&nbsp;&nbsp;&nbsp;end,<br />
&nbsp;&nbsp;ok = try letter_grade(a)<br />
&nbsp;&nbsp;&nbsp;catch throw:invalid_grade -&gt; ok;<br />
&nbsp;&nbsp;&nbsp;&nbsp;_:_ -&gt; fail<br />
&nbsp;&nbsp;&nbsp;end.</p>
<p>check_grade(Grade, Start, End) -&gt;<br />
&nbsp;&nbsp;lists:map(fun(G) -&gt; Grade = letter_grade(G) end,<br />
&nbsp;&nbsp;&nbsp;lists:seq(Start, End)),<br />
&nbsp;&nbsp;ok.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mitchell Hashimoto</title>
		<link>http://www.programmersparadox.com/2008/09/14/javabeyond/comment-page-1/#comment-1787</link>
		<dc:creator>Mitchell Hashimoto</dc:creator>
		<pubDate>Mon, 15 Sep 2008 15:25:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.programmersparadox.com/?p=309#comment-1787</guid>
		<description>Ah! I&#039;m very glad that Kevin Smith included testing in his! :) That alone makes it my favorite.</description>
		<content:encoded><![CDATA[<p>Ah! I&#8217;m very glad that Kevin Smith included testing in his! <img src='http://www.programmersparadox.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  That alone makes it my favorite.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.programmersparadox.com/2008/09/14/javabeyond/comment-page-1/#comment-1786</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Mon, 15 Sep 2008 15:04:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.programmersparadox.com/?p=309#comment-1786</guid>
		<description>Steve, it&#039;s been done.  Sorry about the mess.</description>
		<content:encoded><![CDATA[<p>Steve, it&#8217;s been done.  Sorry about the mess.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Vinoski</title>
		<link>http://www.programmersparadox.com/2008/09/14/javabeyond/comment-page-1/#comment-1785</link>
		<dc:creator>Steve Vinoski</dc:creator>
		<pubDate>Mon, 15 Sep 2008 14:57:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.programmersparadox.com/?p=309#comment-1785</guid>
		<description>Hi Mark, the code I submitted shows up completely wrong, and it won&#039;t even compile if you cut and paste it. Can you either replace the previous comment or delete it, and let&#039;s try again:

&lt;code&gt;-module(grades).
-export([letter_grade/1]).

letter_grade(N)
&#160;when is_integer(N), N &gt;= 0, N =&lt; 100 -&gt;
&#160;&#160;L = [&quot;F&quot;, &quot;F&quot;, &quot;F&quot;, &quot;F&quot;, &quot;F&quot;, &quot;F&quot;, &quot;D&quot;,
&#160;&#160;&#160;&quot;C&quot;, &quot;B&quot;, &quot;A&quot;, &quot;A&quot;],
&#160;&#160;lists:nth(trunc(N/10)+1, L);
letter_grade([G&#124;_]=L)
&#160;when length(L) == 1, G &gt;= $A, G =&lt; $F, G =/= $E -&gt;
&#160;&#160;L;
letter_grade([G&#124;_]=L)
&#160;when length(L) == 1, G &gt;= $a, G =&lt; $f, G =/= $e -&gt;
&#160;&#160;string:to_upper(L);
letter_grade(Grade) -&gt;
&#160;&#160;throw(
&#160;&#160;&#160;lists:flatten(
&#160;&#160;&#160;&#160;io_lib:format(&quot;~p: not a valid grade&quot;,
&#160;&#160;&#160;&#160;&#160;[Grade]))).&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Hi Mark, the code I submitted shows up completely wrong, and it won&#8217;t even compile if you cut and paste it. Can you either replace the previous comment or delete it, and let&#8217;s try again:</p>
<p><code>-module(grades).<br />
-export([letter_grade/1]).</p>
<p>letter_grade(N)<br />
&nbsp;when is_integer(N), N &gt;= 0, N =&lt; 100 -&gt;<br />
&nbsp;&nbsp;L = ["F", "F", "F", "F", "F", "F", "D",<br />
&nbsp;&nbsp;&nbsp;"C", "B", "A", "A"],<br />
&nbsp;&nbsp;lists:nth(trunc(N/10)+1, L);<br />
letter_grade([G|_]=L)<br />
&nbsp;when length(L) == 1, G &gt;= $A, G =&lt; $F, G =/= $E -&gt;<br />
&nbsp;&nbsp;L;<br />
letter_grade([G|_]=L)<br />
&nbsp;when length(L) == 1, G &gt;= $a, G =&lt; $f, G =/= $e -&gt;<br />
&nbsp;&nbsp;string:to_upper(L);<br />
letter_grade(Grade) -&gt;<br />
&nbsp;&nbsp;throw(<br />
&nbsp;&nbsp;&nbsp;lists:flatten(<br />
&nbsp;&nbsp;&nbsp;&nbsp;io_lib:format("~p: not a valid grade",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Grade]))).</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.programmersparadox.com/2008/09/14/javabeyond/comment-page-1/#comment-1784</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Mon, 15 Sep 2008 14:04:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.programmersparadox.com/?p=309#comment-1784</guid>
		<description>All right, I think I&#039;ve gotten everyone&#039;s code formatted properly.  This is a problem I&#039;m going to have to look into more in the future, but for now, if I&#039;ve missed something or miss-handled your code, let me know.

Thanks.</description>
		<content:encoded><![CDATA[<p>All right, I think I&#8217;ve gotten everyone&#8217;s code formatted properly.  This is a problem I&#8217;m going to have to look into more in the future, but for now, if I&#8217;ve missed something or miss-handled your code, let me know.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Smith</title>
		<link>http://www.programmersparadox.com/2008/09/14/javabeyond/comment-page-1/#comment-1783</link>
		<dc:creator>Kevin Smith</dc:creator>
		<pubDate>Mon, 15 Sep 2008 13:46:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.programmersparadox.com/?p=309#comment-1783</guid>
		<description>Here&#039;s my crack at it with a more Erlang-y flavor:

&lt;code&gt;&lt;pre&gt;
-module(grades).
-compile([export_all]).
-define(VALID_GRADES, [&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;F&quot;]).

grade(N) when is_integer(N), N &gt;= 90 -&gt; &quot;A&quot;;
grade(N) when is_integer(N), N &gt;= 80 -&gt; &quot;B&quot;;
grade(N) when is_integer(N), N &gt;= 70 -&gt; &quot;C&quot;;
grade(N) when is_integer(N), N &gt;= 60 -&gt; &quot;D&quot;;
grade(N) when is_integer(N), N &gt;= 0 -&gt; &quot;F&quot;;
grade(N) when is_list(N), length(N) == 1 -&gt; Target = string:to_upper(N),
  case lists:member(Target, ?VALID_GRADES) of
    true -&gt; Target;
    false -&gt; throw(invalid_grade)
  end;
grade(_) -&gt; throw(invalid_grade).
test() -&gt;
  case
    grade(91) =:= &quot;A&quot; andalso
    grade(87) =:= &quot;B&quot; andalso
    grade(72) =:= &quot;C&quot; andalso
    grade(42) =:= &quot;F&quot; andalso
    grade(&quot;c&quot;) =:= &quot;C&quot; andalso
    grade(&quot;A&quot;) =:= &quot;A&quot; of
    true -&gt;
      try
	grades:grade(&quot;q&quot;),
	io:format(&quot;Tests fail...~n&quot;)
      catch
	_ : invalid_grade -&gt;
	  io:format(&quot;Tests pass...~n&quot;)
      end;
    false -&gt;
      io:format(&quot;Tests fail...~n&quot;)
  end.

&lt;/pre&gt;&lt;/code&gt;

Looks like the formatting is off in your comments -- indent as needed.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s my crack at it with a more Erlang-y flavor:</p>
<p><code>
<pre>
-module(grades).
-compile([export_all]).
-define(VALID_GRADES, ["A", "B", "C", "D", "F"]).

grade(N) when is_integer(N), N &gt;= 90 -&gt; "A";
grade(N) when is_integer(N), N &gt;= 80 -&gt; "B";
grade(N) when is_integer(N), N &gt;= 70 -&gt; "C";
grade(N) when is_integer(N), N &gt;= 60 -&gt; "D";
grade(N) when is_integer(N), N &gt;= 0 -&gt; "F";
grade(N) when is_list(N), length(N) == 1 -&gt; Target = string:to_upper(N),
  case lists:member(Target, ?VALID_GRADES) of
    true -&gt; Target;
    false -&gt; throw(invalid_grade)
  end;
grade(_) -&gt; throw(invalid_grade).
test() -&gt;
  case
    grade(91) =:= "A" andalso
    grade(87) =:= "B" andalso
    grade(72) =:= "C" andalso
    grade(42) =:= "F" andalso
    grade("c") =:= "C" andalso
    grade("A") =:= "A" of
    true -&gt;
      try
	grades:grade("q"),
	io:format("Tests fail...~n")
      catch
	_ : invalid_grade -&gt;
	  io:format("Tests pass...~n")
      end;
    false -&gt;
      io:format("Tests fail...~n")
  end.
</pre>
<p></code></p>
<p>Looks like the formatting is off in your comments &#8212; indent as needed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
