On 13 October 2012 22:39, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Sun, Oct 14, 2012 at 6:06 AM, Joshua Landau<br>
<<a href="mailto:joshua.landau.ws@gmail.com">joshua.landau.ws@gmail.com</a>> wrote:<br>
> The fact that your proposal can't allow "a=[]\nfor x in range(10):<br>
> a.append(x**a[-2])\nprint(a)" makes it somewhat an incomplete suggestion,<br>
> and code like:<br>
><br>
>> while True: while True: break; break<br>
><br>
> is just confusing.<br>
<br>
</div>Agreed. However, I don't think there's going to be _any_ perfect<br>
solution for delimiting blocks, short of "from __future__ import<br>
braces".</blockquote><div><br></div><div>I don't know. I don't personally think of it as much of a problem, as the only time this will ever really cause trouble is:</div><div>a) You can't enter newlines easily</div>
<div>b) It's a hassle to keep track of indentation</div><div><br></div><div>These only really apply to a few things.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">
> I don't want to sound closed, but the options I'm really open to are:<br>
><br>
> a) It does a limited set of things that make a those things nicer, á la "@"<br>
> b) It does almost everything, minus some carefully-chosen things deemed to<br>
> quirky, á la current newlines (which don't allow "if a: if b: pass")<br>
> c) It does everything that would be possible<br>
><br>
> Your example falls nicely between a and b, which I do not find particularly<br>
> helpful. Mine attempts a by only applying to "python -c", but would be c if<br>
> it didn't. I find the syntax to horrible for general code, which is why I<br>
> didn't suggest that.<br>
><br>
<br>
</div>Your idea is an extension to the -c parameter that would technically<br>
work, but be fairly hard to manage in anything other than the trivial<br>
case. My idea is an extension to general syntax that would work in all<br>
cases where you aren't trying to put a statement after the end of what<br>
would be an indented block. Both have their limitations, but both<br>
would be - as far as I can see - backward compatible.</blockquote><div><br></div><div>Since you seem to want to solve the general case (I was under the assumption that we were still only talking in the context of the OP) I have an idea.</div>
<div><br></div><div>There could be a Python module that reads a file like this:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font face="courier new, monospace">if a: ${ print(1) $ print(2) $ while b: c() $ if g: ${ pass }$ }$ print(d)</font></blockquote></div>and transforms it to the valid Python:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font face="courier new, monospace">if a:<br> print(1)<br> print(2)<br> while b: c()<br> if g:<br> pass<br>print(d)</font></blockquote><div><br></div><div>That is <b>also</b> callable from the command-line like so:</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">python -m debrace -c "<span style="font-family:'courier new',monospace">if a: ${ print(1) $ print(2) $ while b: c() $ if g: ${ pass }$ }$ print(d)"</span></blockquote>
<div><br></div><div>This should solve both <b>a</b> and <b>b</b> above, and it would make life easier for scripters. It's also easy to mock up, and from then we only need it in the stdlib.</div><div><br></div><div>~~~~~~~~~~~~~~~~~~~~~~~</div>
<div>"${" means INDENT</div><div>"}$" means DEDENT</div><div>"$" means NEWLINE (similar to ";")</div><div><i>"$" has a lower precedence than "${" or "}$"</i></div>