<?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"
	>
<channel>
	<title>Comments on: An Enumeration of Prime Numbers with Anonymous Methods</title>
	<atom:link href="http://blogs.teamb.com/craigstuntz/2008/08/28/37831/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/</link>
	<description>C# • Entity Framework • Functional Programming • MVC • Web</description>
	<pubDate>Sun, 12 Feb 2012 04:15:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Anonymous Methods e Closures no Delphi 2009 &#124; TechTips</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/#comment-20026</link>
		<dc:creator>Anonymous Methods e Closures no Delphi 2009 &#124; TechTips</dc:creator>
		<pubDate>Wed, 10 Nov 2010 20:26:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/08/28/37831#comment-20026</guid>
		<description>[...] Craig Stuntz escreveu um exemplo muito interessante utilizando esse método pra implementar o Crivo de Eratóstenes. Ele entrou no [...]</description>
		<content:encoded><![CDATA[<p>[...] Craig Stuntz escreveu um exemplo muito interessante utilizando esse método pra implementar o Crivo de Eratóstenes. Ele entrou no [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Stuntz</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/#comment-3841</link>
		<dc:creator>Craig Stuntz</dc:creator>
		<pubDate>Wed, 17 Sep 2008 13:53:06 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/08/28/37831#comment-3841</guid>
		<description>Weird. Despite having read a lot of Haskell tutorials, I never knew this was a "common" example! :)</description>
		<content:encoded><![CDATA[<p>Weird. Despite having read a lot of Haskell tutorials, I never knew this was a "common" example! <img src='http://blogs.teamb.com/craigstuntz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thehangedman</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/#comment-3840</link>
		<dc:creator>thehangedman</dc:creator>
		<pubDate>Wed, 17 Sep 2008 13:45:41 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/08/28/37831#comment-3840</guid>
		<description>Thank you for very curious example.

One more interesting thing to mention is that actually it's neither the Sieve of Eratosthenes, nor the sieve at all. Here's the fine paper explaining why, with examples in Haskell:

http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
"A much beloved and widely used example showing the elegance and simplicity of lazy functional programming represents itself as “The Sieve of Eratosthenes”. This paper shows that this example is not the sieve, and presents an implementation that actually is."

Anyway your example is great.</description>
		<content:encoded><![CDATA[<p>Thank you for very curious example.</p>
<p>One more interesting thing to mention is that actually it&#8217;s neither the Sieve of Eratosthenes, nor the sieve at all. Here&#8217;s the fine paper explaining why, with examples in Haskell:</p>
<p><a href="http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf" rel="nofollow">http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf</a><br />
"A much beloved and widely used example showing the elegance and simplicity of lazy functional programming represents itself as “The Sieve of Eratosthenes”. This paper shows that this example is not the sieve, and presents an implementation that actually is."</p>
<p>Anyway your example is great.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Romkin</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/#comment-3825</link>
		<dc:creator>Romkin</dc:creator>
		<pubDate>Wed, 10 Sep 2008 09:58:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/08/28/37831#comment-3825</guid>
		<description>Great example, thanks.
When Composite = 12 (2*2*4) cycle should be endless.</description>
		<content:encoded><![CDATA[<p>Great example, thanks.<br />
When Composite = 12 (2*2*4) cycle should be endless.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Stuntz</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/#comment-3810</link>
		<dc:creator>Craig Stuntz</dc:creator>
		<pubDate>Tue, 02 Sep 2008 13:44:26 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/08/28/37831#comment-3810</guid>
		<description>Raymond, I'll show something along those lines when I get the chance.</description>
		<content:encoded><![CDATA[<p>Raymond, I&#8217;ll show something along those lines when I get the chance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Stuntz</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/#comment-3809</link>
		<dc:creator>Craig Stuntz</dc:creator>
		<pubDate>Tue, 02 Sep 2008 13:43:38 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/08/28/37831#comment-3809</guid>
		<description>Jolyon, if you're seriously interested in learning why it's worthwhile to bother with functional programming styles, I recommend reading the writings of John Backus, starting with his Turing award address.</description>
		<content:encoded><![CDATA[<p>Jolyon, if you&#8217;re seriously interested in learning why it&#8217;s worthwhile to bother with functional programming styles, I recommend reading the writings of John Backus, starting with his Turing award address.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jolyon Smith</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/#comment-3797</link>
		<dc:creator>Jolyon Smith</dc:creator>
		<pubDate>Sat, 30 Aug 2008 22:45:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/08/28/37831#comment-3797</guid>
		<description>Oops, quite right Craig - I didn't spot the mutation of Composite.  I guess I find it easier to read code whose expression more closely resembles it's purpose:

function LargestPrimeFactor(const aComposite: Int64): Int64;
var
  i: Integer;
  primes: TEratosthenesSieve;
begin
  primes := TEratosthenesSieve.CreatePrimesTo(Round(Sqrt(aComposite + 0.0)));
  try
    for i := Pred(primes.Count) downto 0 do
      if (aComposite mod primes[i]) = 0 then
      begin
        result := primes[i];
        BREAK;
      end;
  finally
    primes.Free;
  end;
end;

(apologies for the literals-gymnastics required to co-erce an Extended value from an Int64 param - is that fixed in Delphi 2009 I wonder?)

i.e. the algorithm is - get the primes that the answer could possibly be, then find the largest one that is the answer.  The code describes the algorithm, I don't have to deduce it.

Funny thing - I thought these new language features were supposed to enable us to more clearly express intent, not unwittingly obfuscate it.

;)
 


Isn't there also a hidden cost in an enumerator based approach?

With my TEratosthenesSieve, if I have a number of operations that involve a certain sequence of primes, I only need to calculate that sequence once.  With an enumerator, won't I be re-calculating the primes over and over again (every separate time that I enumerate)?

An enumerator approach would perhaps be useful when you don't know in advance how many primes you are going to need, but even then, a non-enumerating sieve implementation could easily be extended to calculate primes on demand.

Which rather begs the question, what benefit does an enumerating approach really deliver?

Apart from providing a hook off of which to hang some new language features, I mean.

And if such questionable uses are what the language features are useful for, what use are those features, really?

I'm not saying that those features don't have practical uses, only suggesting that such examples don't actually help shed any light on what those uses are.  And concrete, practical examples do seem rather hard to come by for some reason.</description>
		<content:encoded><![CDATA[<p>Oops, quite right Craig - I didn&#8217;t spot the mutation of Composite.  I guess I find it easier to read code whose expression more closely resembles it&#8217;s purpose:</p>
<p>function LargestPrimeFactor(const aComposite: Int64): Int64;<br />
var<br />
  i: Integer;<br />
  primes: TEratosthenesSieve;<br />
begin<br />
  primes := TEratosthenesSieve.CreatePrimesTo(Round(Sqrt(aComposite + 0.0)));<br />
  try<br />
    for i := Pred(primes.Count) downto 0 do<br />
      if (aComposite mod primes[i]) = 0 then<br />
      begin<br />
        result := primes[i];<br />
        BREAK;<br />
      end;<br />
  finally<br />
    primes.Free;<br />
  end;<br />
end;</p>
<p>(apologies for the literals-gymnastics required to co-erce an Extended value from an Int64 param - is that fixed in Delphi 2009 I wonder?)</p>
<p>i.e. the algorithm is - get the primes that the answer could possibly be, then find the largest one that is the answer.  The code describes the algorithm, I don&#8217;t have to deduce it.</p>
<p>Funny thing - I thought these new language features were supposed to enable us to more clearly express intent, not unwittingly obfuscate it.</p>
<p> <img src='http://blogs.teamb.com/craigstuntz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Isn&#8217;t there also a hidden cost in an enumerator based approach?</p>
<p>With my TEratosthenesSieve, if I have a number of operations that involve a certain sequence of primes, I only need to calculate that sequence once.  With an enumerator, won&#8217;t I be re-calculating the primes over and over again (every separate time that I enumerate)?</p>
<p>An enumerator approach would perhaps be useful when you don&#8217;t know in advance how many primes you are going to need, but even then, a non-enumerating sieve implementation could easily be extended to calculate primes on demand.</p>
<p>Which rather begs the question, what benefit does an enumerating approach really deliver?</p>
<p>Apart from providing a hook off of which to hang some new language features, I mean.</p>
<p>And if such questionable uses are what the language features are useful for, what use are those features, really?</p>
<p>I&#8217;m not saying that those features don&#8217;t have practical uses, only suggesting that such examples don&#8217;t actually help shed any light on what those uses are.  And concrete, practical examples do seem rather hard to come by for some reason.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raymond</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/#comment-3793</link>
		<dc:creator>Raymond</dc:creator>
		<pubDate>Fri, 29 Aug 2008 20:08:43 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/08/28/37831#comment-3793</guid>
		<description>Thanks Craig.

You know, with all the confusion of generics, and the examples being posted of how to use them being somewhat artificial, what we really need is an implementation of something a little more concrete/real world for us all to sink our teeth into and appreciate generics with.

Something like a MapReduce would be cool!

Raymond.</description>
		<content:encoded><![CDATA[<p>Thanks Craig.</p>
<p>You know, with all the confusion of generics, and the examples being posted of how to use them being somewhat artificial, what we really need is an implementation of something a little more concrete/real world for us all to sink our teeth into and appreciate generics with.</p>
<p>Something like a MapReduce would be cool!</p>
<p>Raymond.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Stuntz</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/#comment-3782</link>
		<dc:creator>Craig Stuntz</dc:creator>
		<pubDate>Fri, 29 Aug 2008 11:40:54 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/08/28/37831#comment-3782</guid>
		<description>Raymond, I doubt there's any limit beyond the stack size. That said, for 1/2 of the numbers tested (the evens) the method exits immediately, and so on, so you rarely get very deep. Most functional languages will do an optimization called tail recursion which will allow calls on the last line of a method without blowing up the stack, removing this limitation.

Primoz, I know that the composite is non-prime per the problem statement. In the general sense, I'd agree, but I wasn't trying to solve a general problem (and, hence, the hard-coded value). Rather, I was trying to solve problem 3 of Project Euler.</description>
		<content:encoded><![CDATA[<p>Raymond, I doubt there&#8217;s any limit beyond the stack size. That said, for 1/2 of the numbers tested (the evens) the method exits immediately, and so on, so you rarely get very deep. Most functional languages will do an optimization called tail recursion which will allow calls on the last line of a method without blowing up the stack, removing this limitation.</p>
<p>Primoz, I know that the composite is non-prime per the problem statement. In the general sense, I&#8217;d agree, but I wasn&#8217;t trying to solve a general problem (and, hence, the hard-coded value). Rather, I was trying to solve problem 3 of Project Euler.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gabr</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/08/28/37831/#comment-3781</link>
		<dc:creator>gabr</dc:creator>
		<pubDate>Fri, 29 Aug 2008 06:35:50 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/08/28/37831#comment-3781</guid>
		<description>@Craig: And what if the composite is a prime number? You should still stop at the square root.</description>
		<content:encoded><![CDATA[<p>@Craig: And what if the composite is a prime number? You should still stop at the square root.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

