[Python-ideas] allow line break at operators

Yingjie Lan lanyjie at yahoo.com
Sat Sep 3 12:50:30 CEST 2011


Oops, the generating text part of my reply is referring to your last code example. For literal texts, it is is not governed by this proposal, nor are expressions within brackets and backslash continued lines. In a word, this proposal is fully backward compatible.



>________________________________
>From: Yingjie Lan <lanyjie at yahoo.com>
>To: Stephen J. Turnbull <stephen at xemacs.org>
>Cc: python list <python-list at python.org>; Gabriel AHTUNE <gahtune at gmail.com>; python-ideas <python-ideas at python.org>; Matt Joiner <anacrolix at gmail.com>
>Sent: Saturday, September 3, 2011 6:33 PM
>Subject: Re: [Python-ideas] allow line break at operators
>
>
>Ambiguity: yes, when the last line of a suite is a continued line, it would require double dedentations to end the line and the suite. I noticed a similar case in current Python language as well:
>
>
>==================================
>#BEGIN CODE 1
>if condition:
>for i in range(5):
>triangulate(i)
>else: #double dedentations
>for body in space:
>triangulate(body)
>#double dedentations again
>log('triangulation done')
>#END CODE 1
>==================================
>
>
>
>If lines can be continued by indentation, similar situation would rise:
>
>
>==================================
>#BEGIN CODE 2
>if condition:
>result = [sin(i) for i in range(5)]
>+ [cos(i) for i in range(5)]
>else:
>
>result = [cos(i) for i in range(5)]
>+ [sin(i) for i in range(5)]
>
>
>log('triangulation done')
>#END CODE 2
>==================================
>
>
>
>Generating text example: right, this is a case that can't be handled by standard indentation, unless we only consider full dedentation (dedentation to the exact level of the initial indentation) as the signal of ending the line. Whether to accommodate for such a case might be an issue of debate, but at least we can have such 'freedom' :)
>
>
>
>
>
>>________________________________
>>From: Stephen J. Turnbull <stephen at xemacs.org>
>>To: Yingjie Lan <lanyjie at yahoo.com>
>>Cc: Gabriel AHTUNE <gahtune at gmail.com>; Matt Joiner <anacrolix at gmail.com>; python-ideas <python-ideas at python.org>
>>Sent: Saturday, September 3, 2011 5:29 PM
>>Subject: Re: [Python-ideas] allow line break at operators
>>
>>Yingjie Lan writes:
>>
>>> Python uses indentation for blocks, and by the same mechanism, line
>>> breaking can be accommodated without requiring parenthesis or
>>> ending backslashes.
>>
>>Possibly, but now you have a problem that a dedent has ambiguous
>>meaning.  It might mean that you're ending a suite, or it might mean
>>you're ending a continued expression.  This probably can be
>>disambiguated, but I don't know how easy that will be to do
 perfectly,
>>including in reporting ill-formed programs.
>>
>>> Most people seems to like an indentation on the continuing lines,
>>
>>Most of the time, yes, but sometimes not.  For example, in generating
>>text, it's often useful to dedent substantially so you can have a
>>nearly normal length line in the literal strings being concatenated.
>>Or you might have a pattern like this:
>>
>>    x = long_named_variable_a
>>            - long_named_variable_a_base
>>        + long_named_variable_b
>>            - long_named_variable_b_base
>>
>>which your parser would raise an error on, I presume.  That's not
>>freedom!<wink />
>>
>>
>>
>>
>-- 
>http://mail.python.org/mailman/listinfo/python-list
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110903/2dfcb60d/attachment.html>


More information about the Python-list mailing list