<div class="gmail_quote">On Sat, Jan 14, 2012 at 8:19 AM, Paul Moore <span dir="ltr"><<a href="mailto:p.f.moore@gmail.com">p.f.moore@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">On 14 January 2012 13:57, Annie Liu <<a href="mailto:liu@cs.stonybrook.edu">liu@cs.stonybrook.edu</a>> wrote:<br></div></blockquote><div><br>Hi Annie! (*)<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<div class="im">
> For those two simplest examples, yes, "any" and "all" can be used.<br>
> However, there are two general problems.<br>
><br>
> 1.  The order of coding using "any/all" is the opposite order of<br>
> thinking in one's head.  In our experience, those kinds of simple<br>
> examples are coded much more often using "len" than "any/all".  The<br>
> ordering problem gets worse when quantifications are needed in more<br>
> complex conditions or are nested.<br>
<br>
</div>To be honest, that's a matter of opinion. I find any/all with a<br>
generator expression more readable than your syntax, because I am used<br>
to generator expressions as they are common in Python.<br><div class="im"></div></blockquote><div><br>But Paul, aren't you missing the fact that for the algorithms that Annie and her students want to write, the "witness" concept is essential? I.e. they can't just use any(P(x) for x in xs) because if it returns True, they want to know the x that made P(x) be true. Her ! notation is a (perhaps unpythonic) attempt at exporting this witness from the quantification.<br>

<br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">
> 2.  The much worse problem is when a witness is needed from existential<br>
> quantification.  In my last/third example from a distributed algorithm,<br>
> this is the desired code (recall that ! indicates a bound variable):<br>
><br>
>  while some (!slot_num,p1) in decisions:<br>
>     if some (!slot_num,p2) in proposals has p2 != p1:<br>
>        propose(p2)<br>
>     perform(p1)<br>
<br>
</div>Wow, I find that unreadable!. The ! doesn't read as any sort of<br>
assignment to me. Don't forget that in Python, assignments are<br>
statements and don't get embedded in expressions.</blockquote><div><br>I think she's well aware of that, and proposing to change it. :-)<br><br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

There is no way<br>
you're going to get new syntax that creates an expression which embeds<br>
a hidden assignment accepted into Python.<br></blockquote><div><br>That's your opinion. But this is python-ideas. :-)<br><br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">


I'd offer to re write this in idiomatic Python, but looking at it<br>
closer, I've no idea how to. I don't know what slot_num is meant to<br>
be, at first I thought p1 and p2 were predicates, but then I notice<br>
you are comparing them later.<br>
<br>
Can I suggest you write your example out in Python that works today,<br>
and then show how it looks with your proposed syntax alongside? If you<br>
can't find the "best" way of writing it in existing Python, just write<br>
it however works, no need to try to make it compact, or elegant.<br>
There'll be plenty of people here who will show you how to write<br>
idiomatic Python versions of what you post :-)<br></blockquote></div><br>Actually she gave one in her first post. Here it is again:<br><br>       while {p1 for (s0,p1) in decisions if s0==slot_num}:<br>
           p1 = {p1 for (s0,p1) in decisions if s0==slot_num}.pop()<br>
           for p2 in {p2 for (s0,p2) in proposals if s0==slot_num if p2 != p1}:<br>
<br>Note that the set {p1 for (s0,p1) in decisions if s0==slot_num} is computed twice, once to decide whether to stop, and then again to compute the witness (p1). Obviously this is inefficient, and that's what she's after. To make this same code more efficient in Python, you'd have to do the following, which is natural for us programmers (since we're so used to working around limitations and inefficiencies in the systems we work with) but unnatural for mathematicians, who count to infinity at the drop of a hat:<br>

<br>while True:<br>  temp = {p1 for (s0,p1) in decisions if s0==slot_num}<br>  if not temp:<br>    break<br>  p1 = temp.pop()<br>  for p2 in {p2 for (s0,p2) in proposals if s0==slot_num if p2 != p1}:<br>    <whatever><br>

<br>The 5 tedious lines from "while" through "pop()" would be collapsed into a single line if you could write<br><br>  while some s0, p1 in decisions if s0 == slot_num:<br>  for p2 in {p2 for (s0,p2) in proposals if s0==slot_num if p2 != p1}:<br>


    <whatever><br clear="all"><br>TBH I'm not sure what the !slot_num notation is for -- it appears that<br><br>  while some (!slot_num, p1) in decisions:<br><br>is equivalent in Annie's proposal to<br><br>

  while some s0, p1 in decisions if s0 == slot_num:<br><br>but I'm not sure and it doesn't feel necessary to me.<br><br>Also note that SOME and EACH quantifiers were present in ABC (Python's predecessor: <a href="http://homepages.cwi.nl/~steven/abc/qr.html#TESTS">http://homepages.cwi.nl/~steven/abc/qr.html#TESTS</a>); I dropped them for simplicity, not because I didn't like them. If we wanted to we could have them back (except for the problems of introducing new keywords).<br>

<br>__________<br>(*) See <a href="http://neopythonic.blogspot.com/2011/06/depth-and-breadth-of-python.html">http://neopythonic.blogspot.com/2011/06/depth-and-breadth-of-python.html</a><br><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)<br>

<br>