# [Edu-sig] more card play

kirby urner kirby.urner at gmail.com
Tue Nov 3 17:04:06 CET 2009

```On Mon, Nov 2, 2009 at 8:27 PM, Edward Cherlin <echerlin at gmail.com> wrote:

> Cards: You are right on the merits for combinatory math, but you will
> run into strong cultural aversions.
>
>
Yes, anticipated.  However, the Python subculture has done the necessary
work to publish a Diversity Statement, which has an antibiotic effect
against puritanical bigots (assuming you mean some people have moral hangups
about gambling?).

The State of Oregon funds its education system with inputs from video poker
machines whereas the various tribal sovereignties in this area earn a living
from their resort casinos.

So it's integral to our way of life to teach "casino math" (we don't
necessarily call it "combinatorics" at first, as that just scares people
away, makes 'em think we're only into academic applications whereas of
course nothing could be further from the truth).

> Reverse string in place with new iterator: There is a great deal more
> of this. In the 1980s Hewlett-Packard built an APL system around such
>

Yes, the idea of an iterable goes hand-in-hand with the Pythonic notion of a
generator.  Both support the "next" API, a keyword you might assign another
name to if you like.  I've recommended "kick" as in "kick the can down the
road", with each use generating a next term in some famous (or not famous)
sequence:

>>> def cubocta():
n = 0
while True:  # infinite loop OK!
if n == 0:
yield 1
else:
yield 10 * n * n + 2
n += 1

>>> kick = next
>>> can = cubocta()
>>> kick(can)
1
>>> kick(can)
12
>>> kick(can)
42
>>> kick(can)
92
>>> kick(can)
162
>>>

See:  http://www.research.att.com/~njas/sequences/A005901 (note link to
virus morphology)

In the example below, I'm showing how "nexting" through an iterable is a
lazy evaluation affair in that I'm changing the first member of the list
*after* assigning a name to the iterator.  By the time the iterator reaches
the first member of the list, the value has changed from when it started.

>>> some_list = [1,2,3,4,5]
>>> iterable = reversed(some_list)
>>> next(iterable)
5
>>> some_list[0] = "Joker!"
>>> next(iterable)
4
>>> next(iterable)
3
>>> next(iterable)
2
>>> next(iterable)
'Joker!'

Notice that two iterators have their separate journeys through the target
object i.e. advancing one of them doesn't have any affect on the other:

>>> some_list = [1,2,3,4,5]
>>> iterableA = reversed(some_list)
>>> iterableB = reversed(some_list)
>>> next(iterableA)
5
>>> next(iterableA)
4
>>> next(iterableA)
3
>>> next(iterableA)
2
>>> next(iterableA)
1
>>> some_list[0] = "Joker!"
>>> next(iterableB)
5
>>> next(iterableB)
4
>>> next(iterableB)
3
>>> next(iterableB)
2
>>> next(iterableB)
'Joker!'
>>>

Of course strings are immutable so you can't play quite the same trick, of
messing with the target string before the reversed iterator reaches the
beginning.

In the case of my Deck and Card classes, the cloned deck had its own
complete list in reversed order (an option), however the underlying Card
objects were identical across lists, as I was showing by using the "is"
operator.

> transformations in place and lazy evaluation rules, including
> matrix/table transpose, take, drop, catenate, laminate, and a number
> of other transformations and combinations. I can probably dig out
> Harry Saal's paper on the subject. Indeed, that and several others.
>
>
> http://portal.acm.org/citation.cfm?id=801218&dl=GUIDE&coll=GUIDE&CFID=59626041&CFTOKEN=28525913
> An APL compiler for the UNIX timesharing system
>
>
> http://portal.acm.org/citation.cfm?id=586034&dl=GUIDE&coll=GUIDE&CFID=59626133&CFTOKEN=77609109
> Considerations in the design of a compiler for APL
>
> http://portal.acm.org/citation.cfm?id=804441
> A software high performance APL interpreter
>
>
I've always thought Python had a lot in common with APL, especially in terms
of how it organizes a lot of highly orthogonal built-in primitives to
inter-operate in logically consistent ways.  I was privileged to collaborate
a little with Kenneth Iverson on my 'Jiving in J' paper.  To this day, I
recommend J as a second language, as I think a competent CS0/CS1 would never
feature just a single programming language (too narrowing), even if it makes
one primary and the other secondary.  A more traditional option is to
feature one agile and one system language, e.g. Python and C, or Jython and
Java.

Kirby
4D

> On Sun, Nov 1, 2009 at 19:55, kirby urner <kirby.urner at gmail.com> wrote:
> > I'm becoming more enamored of the idea of using playing cards as a
> > standard feature in my Python pedagogy and andragogy (means teaching
> > adults).  Not only do we have the standard deck, but also Tarot which
> > could get us more into text files, string substitution
> > (string.Template) and so forth.
> >
> > Cards have all the elements
>

...

> --
> Edward Mokurai (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) Cherlin
> Silent Thunder is my name, and Children are my nation.
> The Cosmos is my dwelling place, the Truth my destination.
> http://www.earthtreasury.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20091103/fa9cce3f/attachment.htm>
```

More information about the Edu-sig mailing list