[Python-ideas] Adding "Typed" collections/iterators to Python

Joshua Landau joshua.landau.ws at gmail.com
Mon Dec 19 21:37:58 CET 2011


On 19 December 2011 19:26, Nathan Rice <nathan.alexander.rice at gmail.com>wrote:

> On Mon, Dec 19, 2011 at 1:01 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> > Nathan Rice wrote:
> >>
> >> [[1, 2], [3, 4], [5, 6]] could serve as an alternate
> >> example of why you can't directly map child methods with the same
> >> names.
> >
> >
> > If you have to change the names, doesn't that negate the ability of "a
> > reliable method to make functions operate on both scalar and
> > vector values"?
>
> To clarify...
>
> Functions could reliably support both vector and scalar context, by
> checking that a type contract exists.
>
> Because of the name clash between parent and elementwise member
> methods when dealing with collections of collections (and some other
> classes), if the type contract provided "broadcast" versions of child
> methods, they would have to be provided with under an alias, perhaps X
> -> elementwise_X.  I do not think people should be able to be
> oblivious of when they are calling collection and member methods, that
> encourages sloppy programming.  I like the broadcast feature because
> it makes it easier to write code in a clear left to right narrative
> style, and that seems very pythonic to me compared with an
> "inside-out" style.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>

...or we could just extend Pep
225<http://www.python.org/dev/peps/pep-0225/> (deferred) with
"~." so we have "['a', 'b', 'c']~.upper()" [syntax debatable]. You don't
get the type-checking but that seemed more of a problem to me, as I'm not a
real duck.

Your example:
my_string.split("\n").capitalize().join_items("\n")
to
"\n".join(my_string.split("\n")~.capitalize())

And personally I like "string.join(lst)" over "lst.join_with(string)"...

-- Joshua, pointlessly interjecting once again
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111219/16a48116/attachment.html>


More information about the Python-ideas mailing list