[Python-Dev] Re: Comparison of cyclic objects

Ka-Ping Yee ping@lfw.org
Thu, 13 Apr 2000 17:49:21 -0500 (CDT)


As a reference, here is the corresponding cyclic-structure-comparison
example from a message about E:

    
    ? define tight := [1, tight, "x"]
    # value: [1, ***CYCLE***, x] 

    ? define loose := [1, [1, loose, "x"], "x"]
    # value: [1, ***CYCLE***, x] 

    ? tight == loose
    # value: true 

    ? def map := [tight => "foo"]
    # value: [[1, ***CYCLE***, x] => foo] 

    ? map[loose]
    # value: foo 

    Internally, tight and loose have very different representations.
    However, when both cycles are unwound, they represent the same
    infinite tree. One could say that tight's representation of this
    tree is more tightly wound than loose's representation. However,
    this difference is only in the implementation, not in the
    semantics. The value of tight and loose is only the infinite tree
    they represent. If these trees are the same, then tight and loose
    are ==. 

    Notice that loose prints out according to the tightest winding
    of the tree it represents, not according to the cycle by which
    it represents this tree. Only the tightest winding is finite and
    canonical. 


-- ?!ng