PEP 276 Simple Iterator for ints (fwd)

Paul Jackson pj at sgi.com
Thu Dec 6 16:11:21 EST 2001


David wrote:
|> I redid my lecture notes
|> <http://www.ics.uci.edu/~eppstein/260/011023/> using Greg
|> Ewing's "for lb <= var < ub" syntax in place of my previous
|> "for var in [lb, lb+1, ... ub]".
|> 
|> I'm happy with the result

Ah - you may have exposed my primary concern with this - thanks.

It isn't obvious to me which variables are free and which bound.

All the examples I happened to read earlier in this thread had
only one variable, and used explicit integer constants for the
bounds, as in:

    for 0 <= x < 5:

In that case, it's pretty obvious that 'x' is the free variable.

But in your notes, you have things such as:

    for n > i >= 0:
        for i < j <= n:

Here it seems to rely on some assumption that the middle
term, i or j, is the free variable.  So at least the
following two variants:

    for 0 <= x**2 < 16:		# integers x whose square is in range(16)
    for 0 <= x:			# non-negative integers x

should not be allowed, because they violate the assumption I
just surmised.  Or then the assumption gets more subtle.

And then you lose me.

Pseudo code, such as in David's lecture notes, has the advantage
that it can rely on contectual comments, suggestive variable
names, and the authors descretion to avoid non-trivial cases.
But programming language syntax needs to be parsable by clear
rules, even absent (1) comments, (2) suggestive variable names,
or (3) discrete authors.

-- 

                          I won't rest till it's the best ...
                          Manager, Linux Scalability
                          Paul Jackson <pj at sgi.com> 1.650.933.1373



More information about the Python-list mailing list