[Python-Dev] very slow compare of recursive objects
Martin v. Löwis
martin@v.loewis.de
20 Jan 2003 16:53:51 +0100
Tim Peters <tim.one@comcast.net> writes:
> > Oh yes they can be:
> >
> > >>> L = []
> > >>> t = (L, L)
> > >>> L.append(L)
> > >>>
>
> That's an example of a tuple *containing* a recursive structure; there's
> still no way, starting at t, to get back to t. I think mutation is required
> for that. Like
>
> L = [None]
> t = (L, L)
> L[0] = t
Or, using Guido's example:
>>> L=[]
>>> t=(L,)
>>> L.append(t)
>>> t[0][0] is t
True
> It's not clear that this matters to the recursion-checker, though.
It doesn't: You can't create a tuple that contains itself, except on
the C level (which I would declare a bug in the C code that does so).
So any cycle involving a tuple must involve a non-tuple object as
well.
Regards,
Martin