<?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: Fractals in 10 minutes No. 6: Turtle Snowflake</title>
	<atom:link href="http://www.algorithm.co.il/blogs/programming/python/fractals-in-10-minutes-no-6-turtle-snowflake/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.algorithm.co.il/blogs/computer-science/fractals-in-10-minutes-no-6-turtle-snowflake/</link>
	<description>Algorithms, for the heck of it</description>
	<lastBuildDate>Tue, 21 Jun 2011 21:07:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: Python分形&#8211;Turtle Snowflake &#124; Code之行人</title>
		<link>http://www.algorithm.co.il/blogs/computer-science/fractals-in-10-minutes-no-6-turtle-snowflake/#comment-221</link>
		<dc:creator>Python分形&#8211;Turtle Snowflake &#124; Code之行人</dc:creator>
		<pubDate>Mon, 09 Aug 2010 13:21:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=320#comment-221</guid>
		<description>[...] 有兴趣的同学，可以自己泡泡程序。或者挖掘下其他写法。更多讨论，参考原文   /*Baidu Ads,2010-6-14*/ var cpro_id = &#039;u60297&#039;; [...]</description>
		<content:encoded><![CDATA[<p>[...] 有兴趣的同学，可以自己泡泡程序。或者挖掘下其他写法。更多讨论，参考原文   /*Baidu Ads,2010-6-14*/ var cpro_id = &#39;u60297&#39;; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lorg</title>
		<link>http://www.algorithm.co.il/blogs/computer-science/fractals-in-10-minutes-no-6-turtle-snowflake/#comment-220</link>
		<dc:creator>lorg</dc:creator>
		<pubDate>Wed, 28 Oct 2009 19:42:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=320#comment-220</guid>
		<description>1. I fixed the python bits in your comment. Writing Python in comments is easy: just add [ python ] and [ / python ] blocks (just without the spaces).

2. What you suggest is very reminiscent of lstrings, check out http://www.algorithm.co.il/blogs/index.php/projects/lstrings/ , and older fractal links in my blog for more info.

I&#039;m not sure if it&#039;s clearer than recursion. If presented correctly, recursion may be very intuitive. It might even be explained intuitively using this example! It works much better than sorting :)
Regarding usage of yield - I&#039;d rather avoid it I think, because then you have to do a lot of hand waving to explain it to newbies (you can&#039;t be accurate).

By the way, I really liked the line=forward trick. Maybe the names should be different or the *rest should be changed, but it really explains the idea behind the recursion.</description>
		<content:encoded><![CDATA[<p>1. I fixed the python bits in your comment. Writing Python in comments is easy: just add [ python ] and [ / python ] blocks (just without the spaces).</p>
<p>2. What you suggest is very reminiscent of lstrings, check out <a href="http://www.algorithm.co.il/blogs/index.php/projects/lstrings/" rel="nofollow">http://www.algorithm.co.il/blogs/index.php/projects/lstrings/</a> , and older fractal links in my blog for more info.</p>
<p>I&#8217;m not sure if it&#8217;s clearer than recursion. If presented correctly, recursion may be very intuitive. It might even be explained intuitively using this example! It works much better than sorting :)<br />
Regarding usage of yield &#8211; I&#8217;d rather avoid it I think, because then you have to do a lot of hand waving to explain it to newbies (you can&#8217;t be accurate).</p>
<p>By the way, I really liked the line=forward trick. Maybe the names should be different or the *rest should be changed, but it really explains the idea behind the recursion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Beni Cherniavsky</title>
		<link>http://www.algorithm.co.il/blogs/computer-science/fractals-in-10-minutes-no-6-turtle-snowflake/#comment-219</link>
		<dc:creator>Beni Cherniavsky</dc:creator>
		<pubDate>Wed, 28 Oct 2009 09:05:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=320#comment-219</guid>
		<description>p.s. I don&#039;t know if WordPress can be configured that way,
but in a Pythonic blog, you really want to preserve whitespace in comments.</description>
		<content:encoded><![CDATA[<p>p.s. I don&#8217;t know if WordPress can be configured that way,<br />
but in a Pythonic blog, you really want to preserve whitespace in comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Beni Cherniavsky</title>
		<link>http://www.algorithm.co.il/blogs/computer-science/fractals-in-10-minutes-no-6-turtle-snowflake/#comment-218</link>
		<dc:creator>Beni Cherniavsky</dc:creator>
		<pubDate>Wed, 28 Oct 2009 09:03:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=320#comment-218</guid>
		<description>Cool!
I remember doing similar fractals as execin SICP
[ http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html#%_sec_2.2.4 ]
which takes a functional approach.
So I couldn&#039;t resist to try rewriting it:
[python]
def snowflake(length, line=forward, *rest):
     line(length/3, *rest)
     right(60)
     line(length/3, *rest)
     left(120)
     line(length/3, *rest)
     right(60)
     line(length/3, *rest)
[/python]

Then try:

[python]
snowflake(400)
snowflake(400, snowflake)
snowflake(400, snowflake, snowflake)
[/python]

etc.

The purpose of the exercise was to get away from recursion with terminating condition.
Recursion is cool, but there is a constructive process here that I want to capture directly:
Draw the _/\_ shape, but use $subshape instead of straight lines.

But of course &quot;line=forward, *rest&quot; is way too much magic for a newbie.

&quot;snowflake(400, lambda length: snowflake(length))&quot; is even worse.

So, how can I nicely capture the construction without recursion?  Aha!

[python]
def snowflake(length):
	yield length/3
	right(60)
	yield length/3
	left(120)
	yield length/3
	right(60)
	yield length/3

for a in snowflake(400):
	for b in snowflake(a):
		forward(b)
[/python]

What do you think of this?
It&#039;s as close as Python gets to code blocks - a function with fill-in spaces, &quot;do this where I said yield&quot;.
Can this work better then recursion for newbies?
Can we explain yield/for simply enough?

[I suspect people who know some programming would be more daunted than newbies, because yield is powerful and strange - but newbies don&#039;t have to know that :-]

P.S. http://mathworld.wolfram.com/KochSnowflake.html</description>
		<content:encoded><![CDATA[<p>Cool!<br />
I remember doing similar fractals as execin SICP<br />
[ <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html#%_sec_2.2.4" rel="nofollow">http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html#%_sec_2.2.4</a> ]<br />
which takes a functional approach.<br />
So I couldn&#8217;t resist to try rewriting it:<br />
[python]<br />
def snowflake(length, line=forward, *rest):<br />
     line(length/3, *rest)<br />
     right(60)<br />
     line(length/3, *rest)<br />
     left(120)<br />
     line(length/3, *rest)<br />
     right(60)<br />
     line(length/3, *rest)<br />
[/python]</p>
<p>Then try:</p>
<p>[python]<br />
snowflake(400)<br />
snowflake(400, snowflake)<br />
snowflake(400, snowflake, snowflake)<br />
[/python]</p>
<p>etc.</p>
<p>The purpose of the exercise was to get away from recursion with terminating condition.<br />
Recursion is cool, but there is a constructive process here that I want to capture directly:<br />
Draw the _/\_ shape, but use $subshape instead of straight lines.</p>
<p>But of course &#8220;line=forward, *rest&#8221; is way too much magic for a newbie.</p>
<p>&#8220;snowflake(400, lambda length: snowflake(length))&#8221; is even worse.</p>
<p>So, how can I nicely capture the construction without recursion?  Aha!</p>
<p>[python]<br />
def snowflake(length):<br />
	yield length/3<br />
	right(60)<br />
	yield length/3<br />
	left(120)<br />
	yield length/3<br />
	right(60)<br />
	yield length/3</p>
<p>for a in snowflake(400):<br />
	for b in snowflake(a):<br />
		forward(b)<br />
[/python]</p>
<p>What do you think of this?<br />
It&#8217;s as close as Python gets to code blocks &#8211; a function with fill-in spaces, &#8220;do this where I said yield&#8221;.<br />
Can this work better then recursion for newbies?<br />
Can we explain yield/for simply enough?</p>
<p>[I suspect people who know some programming would be more daunted than newbies, because yield is powerful and strange - but newbies don't have to know that :-]</p>
<p>P.S. <a href="http://mathworld.wolfram.com/KochSnowflake.html" rel="nofollow">http://mathworld.wolfram.com/KochSnowflake.html</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

