switch recipe?

Tim Peters tim.one at comcast.net
Sat Jul 13 22:51:26 EDT 2002


[Tim]
> ...
> For the same reason, range(10, 10) doesn't complain in Python, or
> string [i:i], etc -- doing nothing gracefully is important because
> there's sometimes nothing that needs be done <wink>.

[Mark McEahern]
> I think I'll continue to scratch my head and profit from that observation
> for quite some time.  Thank you.
>
> Profit--or better yet, lose.  My misconceptions, that is.  <wink>

If you can tolerate a little theory, the natural way to define "a sequence
of X" is

1. It's empty.
2. Or it's an X, followed by a sequence of X.

It's the 0 in "0 or more" that gives us empty files and empty lists and
empty generators (etc), and which in turn, e.g., makes "while" loops less
error-prone than "repeat ... until" loops in real life.  A program that
can't tolerate empty input vastly overestimates the real world's interest in
what it's doing <wink>.

> So where I've ended up is a place I'm sure there's some fancy
> name for--but I don't know it.

I don't think there's any overwhelmingly standard terminology in this area.
You make it up as you go along.  Generators are fundamental in the Icon
language (*every* Icon expression is "a generator" in theory, even integer
literals like 3), so that's a good place to look for a consistent set of
names in use for a long time:

    http://www.cs.arizona.edu/icon/






More information about the Python-list mailing list