<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div>My schtick involves a mythical Python5, an add-on to my current courses, wherein we adopt a Model-View-Controller approach, as start with really simple views (i.e. ASCII art), knowing in advance the visualizations will be upgraded, using both render-time and real-time pipelines.  The Model is of "tractors in a field", the controller being the user via interactive Python i.e. a very generic idea of MVC).</div>

<div><br></div></div></blockquote><div><br></div><div>What's important about the Tractor class is it defines an iterator, i.e. has a __next__ as well as __iter__ method.</div><div><br></div><div>In one implementation, the entire Tractor is a generator function, not a class, based around a yield that takes new data through tractor.send( ).  The yield / send syntax is of growing importance in Python, as iterators come into their own.</div>
<div><br></div><div>Here's a simple demo of the yield / send concept:</div><div><br></div><div>from string import ascii_lowercase as lowercase, digits</div><div>from random import choice</div><div><br></div><div>def tumbler(alpha=False):</div>
<div>    while True:</div><div>        if alpha:</div><div>            yield choice(lowercase)</div><div>        else:</div><div>            yield choice(digits)</div><div><br></div><div><br></div><div>print("With reinitialization...")</div>
<div>roller = tumbler()    # numeric roller</div><div>print(next(roller))</div><div>print(next(roller))</div><div><br></div><div>roller = tumbler(True) # alpha roller</div><div>print(next(roller))</div><div>print(next(roller))</div>
<div><br></div><div>def tumbler(alpha=False):</div><div>    """</div><div>    self.send() pipes to yield's recipient</div><div>    """</div><div>    d = {}</div><div>    while True:</div>
<div>        if alpha:</div><div>            d = yield choice(lowercase)</div><div>        else:</div><div>            d = yield choice(digits)</div><div>        if d:</div><div>            alpha = d['alpha']</div>
<div><br></div><div>print("With send")</div><div>roller = tumbler()    # numeric roller</div><div>print(next(roller))</div><div>print(next(roller))</div><div><br></div><div>roller.send({'alpha':True}) # switch!</div>
<div><br></div><div>print(next(roller))</div><div>print(next(roller)) </div><div><br></div><div>In the 2nd version of tumbler, there's a way to switch from numeric</div><div>to alpha tumbler (and back) by sending in a dict.  In the 1st version,</div>
<div>you just have to start another tumbler, initialized differently.</div><div><br></div><div>The default tractor, unlike the default turtle, has some sense of </div><div>mortality i.e. unless you keep feeding it, it becomes inoperable.</div>
<div>Of course it would be easy to subclass a turtle in Pythons exiting</div><div>turtle library to have such an attribute.</div><div><br></div><div>In Logo, a turtle is not "literally" a turtle and you can easily imagine</div>
<div>changing the icon, to a tractor for instance.  In the "tractor art" version,</div><div>a way of teaching both Python and computer related concepts, there</div><div>is more emphasis on taking "tractor" seriously, as a way of extending</div>
<div>the metaphor outward, to the surrounding field and farm.  More of </div><div>a namespace is being claimed.  Generality is lost, but this is not </div><div>"a language" so much as a "theme" for inter-connecting lesson </div>
<div>plans.</div><div><br></div><div>A "tumbler" is not a tractor, more like a tumble weed, but your </div><div>basic tractor is like a Turing device in that it may read and/or write</div><div>a character in its current "cell".  This is how a tractor "plows" its </div>
<div>field, it changes the letters it goes over, as it goes over them</div><div>(a kind of "tilling").  </div><div><br></div><div>As mentioned earlier, things start in ASCII but given the MVC </div><div>overview, when know the visualizations won't need to stay that</div>
<div>primitive.</div><div><br></div><div>Kirby</div><div><br></div></div></div></div>