[Python-ideas] Fwd: quantifications, and tuple patterns

Annie Liu liu at cs.stonybrook.edu
Sat Jan 14 14:57:14 CET 2012


For those two simplest examples, yes, "any" and "all" can be used.
However, there are two general problems.

1.  The order of coding using "any/all" is the opposite order of
thinking in one's head.  In our experience, those kinds of simple
examples are coded much more often using "len" than "any/all".  The
ordering problem gets worse when quantifications are needed in more
complex conditions or are nested.

2.  The much worse problem is when a witness is needed from existential
quantification.  In my last/third example from a distributed algorithm,
this is the desired code (recall that ! indicates a bound variable):

  while some (!slot_num,p1) in decisions: 
     if some (!slot_num,p2) in proposals has p2 != p1: 

"any" is not sufficient to code this easily and clearly.  Such
witnesses are needed in all worklist algorithms.


More information about the Python-ideas mailing list