PEP 285: Adding a bool type

Terry Reedy tejarex at yahoo.com
Tue Apr 9 00:16:36 EDT 2002


"Alex Martelli" <aleax at aleax.it> wrote in message
news:Eeos8.74753$S52.2651788 at news2.tin.it...
> Bengt Richter wrote:
>         ...
> > Well, I guess that depends on how you define "assignment" in
Python.
>
> I don't have to, as the Language Reference sees to that:
> http://www.python.org/dev/doc/devel/ref/assignment.html

This defines an 'assignment statement', which uses an 'assignment
operator'.  'Assignment can be read as a more generic concept whose
definition we do not necessarily agree on.

> It's a serious logical fallacy to reason "assignment statements may
> (among other things) rebind names, therefore what rebinds a name
> is an assignment".  Many bindings occur other than by assignment.
> Would you call a for statement, a def statement, a class statement,
> or an import statement "assignments", because they also rebind
> names?!

In the broad sense, yes.  Realizing that import, def, and class are
syntactic sugar for an underlying assignment process that actually or
potentially could have been written as an explicit assignment
statement was a milestone in my understanding of Python.  All three
are run time functions rather than compile time declarations (which
def and class initially looked like to me).  To wit:

import a #and
a = __import__('a')

do the same thing. Writing 'a' just once, without being quoted, is
handier and allows the 'from' and 'as' extensions.  There is a builtin
class constructor function (I forget the details).  And

def fname(p1, ..., pk): suite # is much nicer than the hypothecal
equivalent
fname = makefunc('fname', ('p1', ..., 'pk'), '''suite''')

For is more complicated since it combines repeated assignment and
looping:

for i in iterable: suite # is now equivalent to something like this:

__seqgen = iter(iterable)
try:
    while 1:
        i = __seqgen.next() # break loop on exception
        suite
except StopIteration: pass

Terry J. Reedy







More information about the Python-list mailing list