a = b = 1 just syntactic sugar?

Steven Taschuk staschuk at telusplanet.net
Thu Jun 5 19:59:46 EDT 2003


Quoth Ed Avis:
> Steven Taschuk <staschuk at telusplanet.net> writes:
  [...] 
> >Yes, I see your point.  However, I don't think anything can be done
> >about it without throwing away the present use of indentation for
> >block delimiting.
> 
> I don't think this is true; if lambda were modified to allow
> assignment, for example, the whole expression would still fit on one
> line.  [...]

That's fine, but then (as mentioned before) the scope problems
come into play.  More to the point, if you want other kinds of
statements, such as try/except, if/else, etc., you need multiple
lines, and the problems then are clear:

> [...] (Of course, a multi-line lambda which used indentation to show
> the function body would be welcome...)

That sounds a lot like def to me.

Of course, you probably want the def statement to be an
expression, so you can write it inline.  That's what I can't see
playing well with indentation syntax.  For example:

    mylist = map(def myfunc(x):
        # body of myfunc
        , range(10))

How far should the body of myfunc be indented?  Can the comma
separating it from the second argument to map be put on the last
line of the body of myfunc?  Can those other arguments?  What if
they themselves include blocks-as-expressions?

And, no matter what your answer to such questions, I cannot
imagine any such nested beast being as easy to read as

    def myfunc(x):
        # ...
    mylist = map(myfunc, range(10))

except in the simplest of cases.

  [...]
> I started writing the code in a recursive, moderately 'functional'
> style to generate this diff function, but was disappointed to find out
> that such a technique could never work in Python (as it currently
> stands).

I'm not sure I understand the difficulty; I'd be interested to see
an example of the code you wanted to write but couldn't.

> [...] There are always workarounds for a missing language feature
> [...] but while in some cases the
> alternative style may be more obvious and more idiomatic, it isn't
> always.)

Indeed.

  [...]
-- 
Steven Taschuk                             staschuk at telusplanet.net
"I may be wrong but I'm positive."  -- _Friday_, Robert A. Heinlein





More information about the Python-list mailing list