On Tue, Jun 7, 2011 at 9:51 PM, michel paul <span dir="ltr">&lt;<a href="mailto:mpaul213@gmail.com">mpaul213@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font face="tahoma,sans-serif"><div>&gt;&gt; def f(n, history = []):</div><div><span style="white-space:pre-wrap">        </span>  history.append(n)</div><div><span style="white-space:pre-wrap">        </span>  return history</div>
<div><br></div><div>&gt;&gt;&gt; f(1)</div><div>[1]</div><div>&gt;&gt;&gt; f(2)</div><div>[1, 2]</div><div>&gt;&gt;&gt; f(3)</div><div>[1, 2, 3]</div><div>&gt;&gt;&gt; f(2)</div><div>[1, 2, 3, 2]</div><div>&gt;&gt;&gt; f(1)</div>

<div>[1, 2, 3, 2, 1]</div><div>&gt;&gt;&gt; f(1,[])</div><div>[1]</div><div><br></div><div>A student wrote me wondering why his function wouldn&#39;t &#39;clear&#39; after being called.  He meant to create an empty list and ended up with something like this.</div>

<div><br></div><div>What&#39;s a good way to explain what&#39;s going on?</div><div><br></div><div>- Michel</div><div><br></div></font></blockquote><div><br></div><div>Yeah good example.</div><div><br></div><div>I talk about the &quot;function mouth&quot; as likewise a &quot;castle gate&quot; where &quot;guards&quot; (the parameters) show up to take the values passed to them (as arguments).  </div>
<div><br></div><div>Some guards aren&#39;t met with a value and so go maybe over to this closet (of default objects) and haul out whatever they&#39;re supposed to work with by default.  </div><div><br></div><div>They might append to it (like your history above). </div>
<div><br></div><div>Any time a value (object) comes in as an argument, they use that instead, but the thing in the closet is always there.</div><div><br></div><div>In a primitive way, functions get to have state between calls in this way, a hint that generators are to come, when the fish will finally walk upon land (generators evolve from functions in this story).</div>
<div><br></div><div>Kirby</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><font face="tahoma,sans-serif"><div></div><div><br></div></font><br>
-- <br><div>==================================<br>&quot;What I cannot create, I do not understand.&quot;</div>
<div><br></div><div>- Richard Feynman</div>==================================<br>&quot;Computer science is the new mathematics.&quot;<div><br></div><div>- Dr. Christos Papadimitriou<br>==================================<br>

</div><br>
<br>_______________________________________________<br>
Edu-sig mailing list<br>
<a href="mailto:Edu-sig@python.org">Edu-sig@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/edu-sig" target="_blank">http://mail.python.org/mailman/listinfo/edu-sig</a><br>
<br></blockquote></div><br>