(Accidentally sent this just to David instead of py-dev. Although Andrew has since clarified that the Set constructor actually accepts an iterable directly. And in that case, his magic would probably work _regardless_ of how PEP-276 was implemented behind the scenes. Something about this aspect of the PEP doesn't sit well with me. . .) David Abrahams wrote: > "Andrew Koenig" <ark at acm.org> writes: > > >>I happened to look at PEP 276 and was struck by the thought that PEP 276 is >>really an implementation of the well-known set-theoretic construction of the >>natural numbers that defines each natural number as the set of all smaller >>ones. In other words, it defines 0 as the empty set, 1 as the set whose >>only element is 0, 2 as the set whose elements are 0 and 1, and so on. >> >>Indeed, under PEP 276, sets.Set(42) would be a set with 42 elements that >>would be exactly the canonical representation of 42. > > > ?? Simple Iterator For Ints ?? > http://www.python.org/peps/pep-0276.html > Are you sure you mean 276? > I think he does. Although I think to get the set Andrew wanted with an int type sporting an __iter__ method, you would need to write sets.Set(*42), rather than just writing '42' on its own. Which actually suggests strongly to me that if PEP-276 were to be implemented, it should be done by special casing ints in for-loop generation rather than by having ints support the iterator protocol. Far too much potential for cryptic usage of the latter approach! And you could still get the set-theoretic representation using a generator expression: sets.Set(x for x in 42) Cheers. Nick. -- Nick Coghlan | Brisbane, Australia Email: ncoghlan at email.com | Mobile: +61 409 573 268
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4