Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17515
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <nathan.alexander.rice@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'attribute': 0.07; 'backwards': 0.07; 'does.': 0.07; 'elements.': 0.07; 'references,': 0.07; 'targets': 0.07; 'attribute.': 0.09; 'normative': 0.09; 'storage.': 0.09; 'tuple': 0.09; 'subject:python': 0.10; 'c++': 0.12; 'def': 0.13; 'meaningful': 0.13; 'thanks!': 0.14; 'argument': 0.15; 'tries': 0.15; '"code': 0.16; '(note': 0.16; 'attribute,': 0.16; 'function)': 0.16; 'idea:': 0.16; 'lookup': 0.16; 'repeatedly,': 0.16; 'subject:case': 0.16; 'syntactic': 0.16; 'tmp': 0.16; 'convert': 0.19; 'header:In-Reply-To:1': 0.22; 'interface': 0.23; 'correct,': 0.23; 'objects,': 0.23; 'otherwise,': 0.25; 'code': 0.25; 'function': 0.27; 'code,': 0.27; 'subject:" ': 0.28; 'bit': 0.28; 'lists': 0.28; 'message-id:@mail.gmail.com': 0.28; 'elements': 0.29; 'looks': 0.29; 'problem': 0.29; 'second': 0.29; 'error': 0.29; 'class': 0.29; 'correct': 0.29; 'collections': 0.30; 'inspiration': 0.30; 'iterating': 0.30; 'received:209.85.210.46': 0.30; 'received:mail-pz0-f46.google.com': 0.30; 'certainly': 0.32; 'go.': 0.32; 'list': 0.32; 'break': 0.32; 'comment': 0.32; 'implement': 0.32; 'actually': 0.33; 'this.': 0.33; 'instead': 0.33; 'there': 0.33; 'agree': 0.33; 'to:addr:python-list': 0.34; 'it.': 0.34; 'someone': 0.34; 'things': 0.34; 'preserve': 0.34; 'languages': 0.35; 'operations': 0.35; 'thank': 0.35; 'something': 0.35; 'subject:/': 0.35; 'subject:lists': 0.36; 'example,': 0.37; 'aspect': 0.37; 'element': 0.37; 'sequence': 0.37; 'to:name :python-list': 0.37; 'two': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'think': 0.37; 'skip:_ 10': 0.37; 'could': 0.37; 'allows': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'useful': 0.38; 'e.g.': 0.39; 'should': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'once': 0.60; 'more': 0.61; 'type': 0.61; 'according': 0.61; 'your': 0.61; 'property': 0.63; 'believe': 0.65; 'share': 0.66; 'today,': 0.69; 'today': 0.70; 'imagine': 0.71; 'access,': 0.74; 'coupled': 0.84; 'nathan': 0.84; 'posing': 0.84; 'subject:Making': 0.84; 'regret': 0.91 |
| 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=VC6swl+BdqCsGS6USyaS6oUjczWWGXZCnVhpAcaxMJg=; b=YQzAf85ENTElvnHBjBBc/zozPAM04Q8H1MmUivgyYrQGrCRYugtSyCTlMat21PzQ+j 5mOREE7toALfX/3CoYI3oDgjnMEWkil4yJOrCoG+9ZDiB6CwVT9D4SOTuj1Jw5z2P+Z5 ipOdk9c+BIFyiTmYwnDFJuAWTpmx84pLuWDpE= |
| MIME-Version | 1.0 |
| In-Reply-To | <q2q3s8-8fu.ln1@satorlaser.homedns.org> |
| References | <mailman.3739.1324057724.27778.python-list@python.org> <q2q3s8-8fu.ln1@satorlaser.homedns.org> |
| Date | Mon, 19 Dec 2011 10:56:21 -0500 |
| Subject | Re: Making the case for "typed" lists/iterators in python |
| From | Nathan Rice <nathan.alexander.rice@gmail.com> |
| To | python-list <python-list@python.org> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3822.1324310185.27778.python-list@python.org> (permalink) |
| Lines | 71 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1324310185 news.xs4all.nl 6840 [2001:888:2000:d::a6]:38421 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:17515 |
Show key headers only | View raw
> I think there are two aspects to your idea: > 1. collections that share a single type > 2. accessing multiple elements via a common interface You are correct, and I now regret posing them in a coupled manner. > Both are things that should be considered and I think both are useful in > some contexts. The former would provide additional guarantees, for example, > you could savely look up an attribute of the type only once while iterating > over the sequence and use it for all elements. Also, I believe you could > save some storage. > > The second aspect would mean that you have a single function call that > targets multiple objects, which is syntactic sugar, but that's a good thing. > To some extent, this looks like a C++ valarray, see e.g. [1] and [2] (note > that I don't trust [1] and that [2] is perhaps a bit outdated), in case you > know C++ and want to draw some inspiration from this. > > Anyway, I believe something like that would already be possible today, which > would give people something they could actually try out instead of just > musing about: > > class ValarrayWrapper(object): > def __init__(self, elements): > self._elements = elements > def map(self, function): > tmp = [function(x) for x in self._elements] > return ValarrayWrapper(tmp) > def apply(self, function) > self._elements[:] = [function(x) for x in self._elements] > > I could even imagine this to implement "generic" attribute lookup by looking > at the first element. If it contains the according attribute, return a proxy > that allows calls to member functions or property access, depending on the > type of the attribute. Thank you for the references, I am always interested to see how other languages solve problems. I have received the "code please" comment repeatedly, I will have to take some time after work today to deliver. >> I believe that "typed" lists that get "demoted" to normal lists with >> a warning on out of type operations preserve this information while >> providing complete backwards compatibility and freedom. > > > I don't think that a warning helps people write correct code, a meaningful > error does. Otherwise, with the same argument you could convert a tuple on > the fly to a list when someone tries to change an element of it. I do agree errors are more normative than warnings. The problem with an error in these circumstances is it will certainly break code somewhere. Perhaps a warning that becomes an error at some point in the future would be the prudent way to go. Thanks! Nathan
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Making the case for "typed" lists/iterators in python Nathan Rice <nathan.alexander.rice@gmail.com> - 2011-12-16 12:48 -0500
Re: Making the case for "typed" lists/iterators in python Roy Smith <roy@panix.com> - 2011-12-16 13:05 -0500
Re: Making the case for "typed" lists/iterators in python Chris Angelico <rosuav@gmail.com> - 2011-12-17 05:25 +1100
Re: Making the case for "typed" lists/iterators in python Arnaud Delobelle <arnodel@gmail.com> - 2011-12-16 18:38 +0000
Re: Making the case for "typed" lists/iterators in python Chris Angelico <rosuav@gmail.com> - 2011-12-17 05:43 +1100
Re: Making the case for "typed" lists/iterators in python Mel Wilson <mwilson@the-wire.com> - 2011-12-16 15:14 -0500
Re: Making the case for "typed" lists/iterators in python Ben Finney <ben+python@benfinney.id.au> - 2011-12-17 07:17 +1100
Re: Making the case for "typed" lists/iterators in python Terry Reedy <tjreedy@udel.edu> - 2011-12-16 17:21 -0500
Re: Making the case for "typed" lists/iterators in python Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2011-12-19 14:16 +0100
Re: Making the case for "typed" lists/iterators in python Nathan Rice <nathan.alexander.rice@gmail.com> - 2011-12-19 10:56 -0500
csiph-web