[Python-ideas] universal set object for use in set manipulation
Nick Coghlan
ncoghlan at gmail.com
Thu Jul 23 23:01:40 CEST 2009
Steven D'Aprano wrote:
> I don't think there is a suitable solution for all of these issues. That
> would mean that set.universal() can't be a real set object, it has to
> be some sort of not-quite-a-set object that doesn't provide the entire
> set interface.
That doesn't strike me as all that different from handling NaN and Inf
values in floating point mathematics though. Would set.universal() need
to be a special object that required special handling in some set
algorithms? Yes, it would, but that doesn't make it an invalid idea.
In fact, treating it like a NaN from the decimal module is probably the
answer to most of those questions: if a valid answer isn't defined,
raise an exception.
The semantics would need to be spelled out clearly however, as would a
position on whether or not to add support for complementary sets (i.e.
sets that are defined as "set.universal() ^ items_not_in_set").
Also the "universal" or "complementary" character of the set would need
to be embodied in mutable state on the set object so that in-place
operations such as "s |= set.universal()" can work correctly.
Cheers,
Nick.
P.S. I'm not necessarily +1, or even +0, on the idea until it is fleshed
out further. I just wanted to point out that there is precedent for
including the numerical equivalents of the universal set.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-ideas
mailing list