Any, All predicates (and vector operations for free)

Steven Taschuk staschuk at telusplanet.net
Tue Feb 18 16:45:55 EST 2003


Quoth Christos TZOTZIOY Georgiou:
> On Mon, 17 Feb 2003 18:24:54 -0700, rumours say that Steven Taschuk
> <staschuk at telusplanet.net> might have written:
  [...]
> >I think I'd prefer a scheme under which I'd write
> >	all(L, lambda x: exists(x, lambda y: y > 2))
> >which is more verbose, but (to me at least) easier to parse.  Also
> >the implementation is trivial, short-circuiting is easy, and no
> >difficult semantic questions arise.  (It's really just a
> >generalization of map, etc., to generic iterables.)
> 
> Yes, although I think the syntax my module allows is much more pleasant
> to the (my :) eye.

Absolutely; your syntax is very appealing...

...at least in simple cases.  Even if these quantifiers could be
composed directly, it's not immediately obvious what
	Any(All(L)) > 2
is supposed to mean.  Also, quantifying at the variable rather
than around the whole statement (as is usual in logic) has
disadvantages when the variable occurs more than once:
	All(L).startswith('a') and All(L).endswith('z')
will spin L twice, which precludes the use of this kind of
expression with generic iterables.

Imho such issues outweigh the impressively sexy syntax, and
motivate something like all(it, func).  (It would be natural to
base such functions on map and filter, if those returned iterators
when their arguments were iterators...  but separate, iterator-
returning versions of map and filter might be best.)

-- 
Steven Taschuk                          staschuk at telusplanet.net
"Its force is immeasurable.  Even Computer cannot determine it."
                            -- _Space: 1999_ episode "Black Sun"





More information about the Python-list mailing list