[Python-ideas] explicitation lines in python ?
geremy condra
debatem1 at gmail.com
Sat Jun 26 08:48:30 CEST 2010
On Fri, Jun 25, 2010 at 11:55 PM, Chris Rebert <pyideas at rebertia.com> wrote:
> On Fri, Jun 25, 2010 at 7:58 PM, Stephen J. Turnbull <stephen at xemacs.org> wrote:
>> Daniel DELAY writes:
>>
>> > (Sorry if this has already been discussed earlier on this list, I have
>> > not read all the archives)
>>
>> I think if you search for "first-class blocks" and "lambdas", or
>> similar, you'll find related discussion (although not exactly the same
>> thing). It also looks very similar to the Haskell "where", maybe
>> searching for "Haskell where" would bring it up.
>>
>> > Renouncing to list comprehension occurs rather often when I write python
>> > code
>> >
>> > I think we could greatly improve readability if we could keep list
>> > comprehension anywhere in all cases, but when necessary explicit a too
>> > complex expression in an indented line :
>> >
>> > htmltable = ''.join( '<tr>{}</tr>'.format(htmlline) for line in table):
>> > htmlline : ''.join( '<td>{}</td>'.format(cell) for cell in line)
>>
>> (Edited for readability; it was munged by your mail client. ;-)
>>
>> I'm not sure I like this better than the alternative of rewriting the
>> outer loops explicitly. But if you're going to add syntax, I think
>> the more verbose
>>
>> htmltable = ''.join('<tr>{}</tr>'.format(htmlline) for line in table) \
>> with htmlline = ''.join('<td>{}</td>'.format(cell) for cell in line)
>>
>> looks better. Note that the "with" clause becomes an optional part of
>> an assignment statement rather than a suite controlled by the
>> assignment, and the indentation is decorative rather than syntactic.
>> I considered "as" instead of "=" in the with clause, but preferred the
>> "=" because that allows nested "with" in a natural way. (Maybe, I
>> haven't thought carefully about that at all.) Obviously "with" was
>> chosen because it's already a keyword.
>>
>> I suspect this has been shot down before, though.
>
> Prior thread:
> [Python-ideas] Where-statement (Proposal for function expressions)
> http://mail.python.org/pipermail/python-ideas/2009-July/005114.html
I was all set to dislike this syntax, but after reading over it a bit I
find myself liking it a lot. Was the code for this (or similar) ever
written, or was it just proposed?
Geremy Condra
More information about the Python-ideas
mailing list