<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Oct 13, 2016 at 11:42 PM Paul Moore <<a href="mailto:p.f.moore@gmail.com">p.f.moore@gmail.com</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I remain puzzled.<br class="gmail_msg">
<br class="gmail_msg">
Given the well-documented and understood transformation:<br class="gmail_msg">
<br class="gmail_msg">
[fn(x) for x in lst if cond]<br class="gmail_msg">
<br class="gmail_msg">
translates to<br class="gmail_msg">
<br class="gmail_msg">
result = []<br class="gmail_msg">
for x in lst:<br class="gmail_msg">
if cond:<br class="gmail_msg">
result.append(fn(x))<br class="gmail_msg">
<br class="gmail_msg">
please can you explain how to modify that translation rule to<br class="gmail_msg">
incorporate the suggested syntax?<br class="gmail_msg"></blockquote><div><br></div><div>if you allow result.append(1, 2, 3) to mean result.extend([1,2,3]) # which was discussed before</div><div><br></div><div>result = []<br class="gmail_msg">for x in lst:<br class="gmail_msg"> if cond:<br class="gmail_msg"> result.append(*fn(x)) </div><div><br></div><div>Or simply use result.extend([*fn(x)])</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Personally, I'm not even sure any more that I can *describe* the<br class="gmail_msg">
suggested syntax. Where in [fn(x) for x in lst if cond] is the *<br class="gmail_msg">
allowed? fn(*x)? *fn(x)? Only as *x with a bare variable, but no<br class="gmail_msg">
expression? Only in certain restricted types of construct which aren't<br class="gmail_msg">
expressions but are some variation on an unpacking construct?<br class="gmail_msg">
<br class="gmail_msg"></blockquote><div><br></div><div>The star is always exactly at the place that should "handle" it. which means [*(fn(x)) for x in lst if cond]. fn(x) must be iterable as always.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
We've had a lot of examples. I think it's probably time for someone to<br class="gmail_msg">
describe the precise syntax (as BNF, like the syntax in the Python<br class="gmail_msg">
docs at <a href="https://docs.python.org/3.6/reference/expressions.html#displays-for-lists-sets-and-dictionaries" rel="noreferrer" class="gmail_msg" target="_blank">https://docs.python.org/3.6/reference/expressions.html#displays-for-lists-sets-and-dictionaries</a><br class="gmail_msg">
and following sections) and semantics (as an explanation of how to<br class="gmail_msg">
rewrite any syntactically valid display as a loop). It'll have to be<br class="gmail_msg">
done in the end, as part of any implementation, so why not now?<br class="gmail_msg">
<br class="gmail_msg"></blockquote><div><br></div><div>I will be happy to do so, and will be happy to work with anyone else interested.</div><div><br></div><div>Elazar</div></div></div>