Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'context': 0.04; 'value,': 0.04; 'motivated': 0.05; 'behavior.': 0.07; 'currently,': 0.07; 'pypy': 0.07; 'tends': 0.07; 'type,': 0.07; 'python': 0.08; 'dynamically': 0.09; 'successive': 0.09; 'subject:python': 0.10; 'read.': 0.10; '16,': 0.15; 'intermediate': 0.15; 'identifiers.': 0.16; 'iterator,': 0.16; 'overrides': 0.16; 'preexisting': 0.16; 'subject:case': 0.16; 'vectors': 0.16; '\xa0this': 0.16; 'examples': 0.16; 'language': 0.17; 'wrote:': 0.18; 'interesting.': 0.18; 'onto': 0.18; 'wrap': 0.18; 'slightly': 0.19; 'this?': 0.19; 'primarily': 0.21; 'appropriate': 0.22; 'dec': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'stops': 0.23; "people's": 0.24; 'stefan': 0.24; 'code': 0.25; 'function': 0.27; 'skip:[ 10': 0.27; 'fact': 0.27; 'url:mailman': 0.28; 'compare': 0.28; 'subject:" ': 0.28; '(you': 0.28; 'lists': 0.28; 'message-id:@mail.gmail.com': 0.28; 'elements': 0.29; 'explicitly': 0.29; 'problem': 0.29; 'pm,': 0.29; 'class': 0.29; 'lines': 0.30; 'keeps': 0.30; 'developers': 0.32; 'does': 0.32; 'done,': 0.32; 'implementing': 0.32; 'list': 0.32; 'url:listinfo': 0.32; 'pretty': 0.32; "isn't": 0.33; 'there': 0.33; 'received:209.85.160': 0.33; 'fri,': 0.34; 'done': 0.34; 'to:addr :python-list': 0.34; 'community': 0.34; 'discussed': 0.34; 'realize': 0.34; 'certain': 0.34; 'anything': 0.34; 'options:': 0.34; 'surprised': 0.34; 'something': 0.35; 'subject:/': 0.35; 'received:209.85.160.46': 0.35; 'received:mail- pw0-f46.google.com': 0.35; 'unless': 0.35; 'url:python': 0.36; 'subject:lists': 0.36; 'to:name:python-list': 0.37; 'but': 0.37; 'list,': 0.37; 'received:google.com': 0.37; 'skip:_ 10': 0.37; 'could': 0.37; 'using': 0.38; 'received:209.85': 0.38; 'couple': 0.38; 'skip:\xa0 10': 0.39; 'clearly': 0.39; 'url:org': 0.39; 'hit': 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'hope': 0.61; 'more': 0.61; '2011': 0.61; 'your': 0.61; 'subject': 0.62; 'direction.': 0.64; 'movement': 0.64; 'stated': 0.68; 'soon': 0.70; 'informative': 0.73; 'analysis': 0.77; 'strategies': 0.82; 'habit': 0.84; 'nathan': 0.84; 'subject:Making': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=IQBddvGALn2XBrlYOY4BNTsCyDswnkeFxdn3Eor9Lq4=; b=ikizruo8Gz+kkN85Bw8BWpQdK+E2SnJ88L49dc/k+IMRULfVesa58o7aML+LX9awjU J9KSsKkY/5ueAMYZB64SeHJaRMOWjFhEKOtTuQvL4TExbKGLtmF1dksiC5jJvh6ZU9f0 UmUTyABIrp+U4894Vp/ymrdfZwFM3Txrxw8zk= MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 16 Dec 2011 13:51:08 -0500 Subject: Re: Making the case for "typed" lists/iterators in python From: Nathan Rice To: python-list Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 71 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324061472 news.xs4all.nl 6867 [2001:888:2000:d::a6]:52245 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17377 Nothing stops me from implementing it, in fact it is VERY trivial to wrap member class methods onto a list subclass, and wrap functions to support vectorized behavior. The problem is that as soon as you hit anything outside your code that returns a list or iterator, everything gets blown away unless you explicitly wrap the return value, which entirely defeats the point. On Fri, Dec 16, 2011 at 1:23 PM, Stefan Behnel wrote: > Nathan Rice, 16.12.2011 18:48: > >> I realize this has been discussed in the past, I hope that I am >> presenting a slightly different take on the subject that will prove >> interesting. =A0This is primarily motivated by my annoyance with using >> comprehensions in certain circumstances. >> >> Currently, if you want to perform successive transformations on the >> elements of a list, a couple of options: >> >> 1. Successive comprehensions: >> >> L2 =3D [X(e) for e in L1] >> L3 =3D [Y(e) for e in L2] >> L4 =3D [Z(e) for e in L3] >> or >> L2 =3D [e.X() for e in L1] >> >> This gets the job done and gives you access to all the intermediate >> values, but isn't very succinct, particularly if you are in the habit >> of using informative identifiers. >> >> 2. One comprehension: >> >> L2 =3D [Z(X(Y(e))) for e in L1] >> or >> L2 =3D [e.X().Y().Z() for e in L1] >> >> This gets the job done, but doesn't give you access to all the >> intermediate values, and tends to be pretty awful to read. >> >> Having "typed" lists let you take preexisting string/int/etc methods >> and expose them in a vectorized context and provides an easy way for >> developers to support both vectors and scalars in a single function >> (you could easily "fix" other people's functions dynamically to >> support both). =A0Additionally, "typed" lists/iterators will allow >> improved code analysis and optimization. =A0The PyPy people have already >> stated that they are working on implementing different strategies for >> lists composed of a single type, so clearly there is already community >> movement in this direction. >> >> Just compare the above examples to their type-aware counterparts: >> >> L2 =3D X(L1) >> L2 =3D L1.X() >> >> L2 =3D Z(Y(X(L1))) >> L2 =3D L1.X().Y().Z() > > > What keeps you from implementing this? You don't need to change the langu= age > for it, just wrap the list in a class that overrides __getattr__() to ret= urn > something that does the appropriate transformation for each element. I wo= uld > be surprised if you needed more than a couple of lines of Python code for > that. > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list