On 1/1/21 9:50 AM, Jonathan Fine wrote: > Hi > > I'd say the problem isn't recursion. Here I'm using the definitions > given in: > https://en.wikipedia.org/wiki/Recursion > <https://en.wikipedia.org/wiki/Recursion> > https://www.cs.utah.edu/~germain/PPS/Topics/recursion.html > <https://www.cs.utah.edu/~germain/PPS/Topics/recursion.html> > > Rather, it's that the data has a loop (or cycle) in it. A simple > example of this is > >>> x = [] > >>> x.append(x) > >>> x > [[...]] > >>> x[0] is x > True > > So far as I know, it's not possible to create such using only > immutable objects. And anything created using only immutable objects > will have a hash. > > A beginner can easily by mistake create an object such as x above, and > without the short-circuit provided by > >>> x > [[...]] > the result is an unprintable object, that further raises an exception > (or worse). That's really bad for the poor beginner. > > As a first approximation, my opinion is that data having such a loop / > cycle in it is at least a code smell, and perhaps worse. However, > there may be examples that I've not considered that would make me > change my mind.
A very simple and in my mind reasonable use for this is to build a representation of a graph, where each node is represented by a list (or some other collection), and the connections are denoted by adding to that collection the nodes that are adjacent (or maybe a tuple of the node and the distance). This naturally creates a recursive structure unless connections are unidirectional and the graph is acyclical (i.e. a tree). For example, a 3 node fully connected graph might be: a = [] b = [] c = [] a.append(b) a.append(c) b.append(a) b.append(c) c.append(a) c.append(b) Maybe more generally the nodes would be dicts of properties, one of which is a connection property with that list of nodes, but you still end up with the same recursion. > > By the way, in the mathematics of the symmetric group (permutations) > the two tuples > >>> (0, 1, 2, 3) > >>> (1, 2, 3, 0) > are different representations of the same cycle (where here the word > cycle has a different meaning). > > Also by the way, determining if two vertex-edge graphs are isomorphic > is a hard problem. I've been told that the best tool for this is > https://www3.cs.stonybrook.edu/~algorith/implement/nauty/implement.shtml > <https://www3.cs.stonybrook.edu/~algorith/implement/nauty/implement.shtml> > > To summarise, it's loops / cycles in the representation of the data > that's the problem. Without a use case to the contrary, I'd say don't > do this. That's my opinion. Yours may be different. > > Final idea. Perhaps a tool to detect cycles in data might be a good idea. > > Finally, Happy New Year. > > -- > Jonathan > -- Richard Damon _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/HC6KXTAD2ROTXRSZXTXD4CVZ25SB2L2Q/ Code of Conduct: http://python.org/psf/codeofconduct/