Re: Nested Mapping

2010-10-22 Thread Steven D'Aprano
On Thu, 21 Oct 2010 16:19:43 -0700, Raymond Hettinger wrote: > I'm considering a nested mapping class for the collections module and > would like to solicit feedback from people here on comp.lang.python: > >http://code.activestate.com/recipes/577434-nested-contexts-a-chain- of-mapping-objects

Re: Nested Mapping

2010-10-22 Thread Ethan Furman
Raymond Hettinger wrote: On Oct 21, 5:18 pm, Paul Rubin wrote: The API you suggested looks reasonable although you should also say how to delete a context, how to find the inner contexts of a context, etc. The c.parent.parent.parent chain finds successive enclosing contexts: while c.paren

Re: Nested Mapping

2010-10-22 Thread Raymond Hettinger
On Oct 21, 6:13 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > The c.parent.parent.parent chain finds successive enclosing contexts: > > I was asking about finding the child contexts, not the parents.  This is > analogous to how you can find the keys in a dict with dict.keys(). Children p

Re: Nested Mapping

2010-10-22 Thread Raymond Hettinger
On Oct 22, 8:48 am, Robert Kern wrote: > On 10/21/10 6:19 PM, Raymond Hettinger wrote: > > > I would appreciate any feedback on the API and on how well it fits > > with various use cases that you've found in the wild. > > We've done something similar in the past: > > https://svn.enthought.com/svn/

Re: Nested Mapping

2010-10-22 Thread Raymond Hettinger
On Oct 22, 4:17 am, Peter Otten <__pete...@web.de> wrote: > I just read the recipe, and it looks good to me except for the len() and > iter() implementations: > > >>> a = Context() > >>> a["x"] = 1 > >>> b = a.new_child() > >>> b["x"] = 2 > >>> len(b) > 2 > >>> b.keys() > > ['x', 'x'] > > I would h

Re: Nested Mapping

2010-10-22 Thread Robert Kern
On 10/21/10 6:19 PM, Raymond Hettinger wrote: I would appreciate any feedback on the API and on how well it fits with various use cases that you've found in the wild. We've done something similar in the past: https://svn.enthought.com/svn/enthought/CodeTools/trunk/enthought/contexts/multi_co

Re: Nested Mapping

2010-10-22 Thread Peter Otten
Raymond Hettinger wrote: > I'm considering a nested mapping class for the collections module and > would like to solicit feedback from people here on comp.lang.python: > >http://code.activestate.com/recipes/577434-nested-contexts-a-chain-of- mapping-objects/ > > The class is an attempt to ge

Re: Nested Mapping

2010-10-21 Thread Arnaud Delobelle
Raymond Hettinger writes: > I'm considering a nested mapping class for the collections module and > would like to solicit feedback from people here on comp.lang.python: > > > http://code.activestate.com/recipes/577434-nested-contexts-a-chain-of-mapping-objects/ > Django has such contexts in

Re: Nested Mapping

2010-10-21 Thread Paul Rubin
Raymond Hettinger writes: > The c.parent.parent.parent chain finds successive enclosing contexts: I was asking about finding the child contexts, not the parents. This is analogous to how you can find the keys in a dict with dict.keys(). >> One question: what should >> >>    c["foo"] = 7 >>    d

Re: Nested Mapping

2010-10-21 Thread Raymond Hettinger
On Oct 21, 5:18 pm, Paul Rubin wrote: > The API you suggested looks reasonable although you should also say how > to delete a context, how to find the inner contexts of a context, etc. The c.parent.parent.parent chain finds successive enclosing contexts: while c.parent is not None: pri

Re: Nested Mapping

2010-10-21 Thread Paul Rubin
Raymond Hettinger writes: > Hopefully, that discussion can be in a separate thread. > This is really about keeping all the nice O(1) characteristics > of dicts and keeping their straight-forward API while adding > the ability to support nested lookups. Are you saying the O(1) characteristics are

Re: Nested Mapping

2010-10-21 Thread Raymond Hettinger
On Oct 21, 4:28 pm, Paul Rubin wrote: > Raymond Hettinger writes: > What I really want is a Haskell-like persistent (i.e. purely functional) > dictionary implemented as an AVL tree or something like that. Hopefully, that discussion can be in a separate thread. This is really about keeping all th

Re: Nested Mapping

2010-10-21 Thread Paul Rubin
Raymond Hettinger writes: > I would appreciate any feedback on the API and on how well it fits > with various use cases that you've found in the wild. What I really want is a Haskell-like persistent (i.e. purely functional) dictionary implemented as an AVL tree or something like that. It means t