Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28739 > unrolled thread

Re: set and dict iteration

Started byThomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
First post2012-09-08 22:06 +0200
Last post2012-09-08 22:22 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: set and dict iteration Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-08 22:06 +0200
    Re: set and dict iteration Hans Mulder <hansmu@xs4all.nl> - 2012-09-08 23:18 +0200
    Re: set and dict iteration MRAB <python@mrabarnett.plus.com> - 2012-09-08 22:22 +0100

#28739 — Re: set and dict iteration

FromThomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Date2012-09-08 22:06 +0200
SubjectRe: set and dict iteration
Message-ID<k2g8fg$fop$1@r03.glglgl.gl>
Am 19.08.2012 00:14 schrieb MRAB:

>> Can someone who is more familiar with the cycle detector and cycle
>> breaker, help prove or disprove the above?
>>
> In simple terms, when you create an immutable object it can contain
> only references to pre-existing objects, but in order to create a cycle
> you need to make an object refer to another which is created later, so
> it's not possible to create a cycle out of immutable objects.

Yes, but if I add a list in-between, I can create a refcycle:

a = []
b = (a,)
a.append(b)

So b is a tuple consisting of one list which in turn contains b.

It is not a direct cycle, but an indirect one.

Or would that be detected via the list?


Thomas

[toc] | [next] | [standalone]


#28745

FromHans Mulder <hansmu@xs4all.nl>
Date2012-09-08 23:18 +0200
Message-ID<504bb625$0$6904$e4fe514c@news2.news.xs4all.nl>
In reply to#28739
On 8/09/12 22:06:08, Thomas Rachel wrote:
> Am 19.08.2012 00:14 schrieb MRAB:
> 
>>> Can someone who is more familiar with the cycle detector and cycle
>>> breaker, help prove or disprove the above?
>>>
>> In simple terms, when you create an immutable object it can contain
>> only references to pre-existing objects, but in order to create a cycle
>> you need to make an object refer to another which is created later, so
>> it's not possible to create a cycle out of immutable objects.
> 
> Yes, but if I add a list in-between, I can create a refcycle:
> 
> a = []
> b = (a,)
> a.append(b)
> 
> So b is a tuple consisting of one list which in turn contains b.
> 
> It is not a direct cycle, but an indirect one.

It's a cycle and it contains an immutable object, but it's not
a cycle consisting of immutable objects only.

As MRAB was arguing: it is not possbible to create a cycle
consisting of immutable objects only (unless you do unspeakable
things at the C level).

-- HansM

[toc] | [prev] | [next] | [standalone]


#28746

FromMRAB <python@mrabarnett.plus.com>
Date2012-09-08 22:22 +0100
Message-ID<mailman.392.1347139563.27098.python-list@python.org>
In reply to#28739
On 08/09/2012 21:06, Thomas Rachel wrote:
> Am 19.08.2012 00:14 schrieb MRAB:
>
>>> Can someone who is more familiar with the cycle detector and cycle
>>> breaker, help prove or disprove the above?
>>>
>> In simple terms, when you create an immutable object it can contain
>> only references to pre-existing objects, but in order to create a cycle
>> you need to make an object refer to another which is created later, so
>> it's not possible to create a cycle out of immutable objects.
>
> Yes, but if I add a list in-between, I can create a refcycle:
>
> a = []
> b = (a,)
> a.append(b)
>
> So b is a tuple consisting of one list which in turn contains b.
>
> It is not a direct cycle, but an indirect one.
>
> Or would that be detected via the list?
>
The quote was:

'''
...The tuple type does not implement a tp_clear function, because it’s 
possible to prove that no reference cycle can be composed entirely of 
tuples.
'''

Note: "composed entirely of tuples".

Or, in general, composed entirely of immutables.

Lists are not immutable, therefore the proof does not apply.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web