<br><br><div class="gmail_quote"><div dir="ltr">בתאריך יום ו׳, 14 באוק' 2016, 12:19, מאת Michel Desmoulin <<a href="mailto:desmoulinmichel@gmail.com">desmoulinmichel@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Regarding all those examples:<br class="gmail_msg">
<br class="gmail_msg">
Le 14/10/2016 à 00:08, אלעזר a écrit :<br class="gmail_msg">
> Trying to restate the proposal, somewhat more formal following Random832<br class="gmail_msg">
> and Paul's suggestion.<br class="gmail_msg">
><br class="gmail_msg">
> I only speak about the single star.<br class="gmail_msg">
> ---<br class="gmail_msg">
><br class="gmail_msg">
> *The suggested change of syntax:*<br class="gmail_msg">
><br class="gmail_msg">
> comprehension ::= starred_expression comp_for<br class="gmail_msg">
><br class="gmail_msg">
> *Semantics:*<br class="gmail_msg">
><br class="gmail_msg">
> (In the following, f(x) must always evaluate to an iterable)<br class="gmail_msg">
><br class="gmail_msg">
> 1. List comprehension:<br class="gmail_msg">
><br class="gmail_msg">
> result = [*f(x) for x in iterable 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 iterable:<br class="gmail_msg">
> if cond:<br class="gmail_msg">
> result.extend(f(x))<br class="gmail_msg">
><br class="gmail_msg">
> 2. Set comprehension:<br class="gmail_msg">
><br class="gmail_msg">
> result = {*f(x) for x in iterable if cond}<br class="gmail_msg">
><br class="gmail_msg">
> Translates to<br class="gmail_msg">
><br class="gmail_msg">
> result = set()<br class="gmail_msg">
> for x in iterable:<br class="gmail_msg">
> if cond:<br class="gmail_msg">
> result.update(f(x))<br class="gmail_msg">
<br class="gmail_msg">
Please note that we already have a way to do those. E.G:<br class="gmail_msg">
<br class="gmail_msg">
result = [*f(x) for x in iterable if cond]<br class="gmail_msg">
<br class="gmail_msg">
can currently been expressed as:<br class="gmail_msg">
<br class="gmail_msg">
>>> iterable = range(10)<br class="gmail_msg">
>>> f = lambda x: [x] * x<br class="gmail_msg">
>>> [y for x in iterable if x % 2 == 0 for y in f(x)]<br class="gmail_msg">
[2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8]<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
Now I do like the new extension syntax. I find it more natural, and more<br class="gmail_msg">
readable:<br class="gmail_msg">
<br class="gmail_msg">
>>> [*f(x) for x in iterable if x % 2 == 0]<br class="gmail_msg">
<br class="gmail_msg">
But it's not a missing feature, it's really just a (rather nice)<br class="gmail_msg">
syntaxic improvement.<br class="gmail_msg"></blockquote></div><div><br></div><div>It is about lifting restrictions from an existing syntax. That this behavior is being *explicitly disabled* in the implementation is a strong evidence, in my mind.</div><div><br></div><div>(There are more restrictions I was asked not to divert this thread, which makes sense) <br><br>Elazar</div>