[Python-ideas] Fwd: Re: Unambiguous repr for recursive objects

Random832 random832 at fastmail.com
Sat Dec 26 19:24:25 EST 2015


Andrew Barnert writes:
> No. 2.x did not provide total information. It used the exact same
> __repr__ as 3.x. (If you can come up with a way to provide total
> information that's readable to both humans and the parser, I'm sure
> everyone would love to see it.)

Emacs Lisp has an option to (and some versions of Javascript used to
borrow the same syntax) represent circular references and duplicate
references with a syntax where the first reference has #N=(whatever) and
other references as #N#. So, a circular list would be #1=(#1#); a list
containing a reference to itself and two references to another list
would be #1=(#1# #2=(3) #2#), etc.

Emacs' parser supports it, Javascript's never did even on the versions
that could produce the format.

When the option is turned off, it substitutes circular references, but
not duplicate references, with #N where N appears the level of nesting
from the top of the expression where the outermost copy of the reference
appears, a syntax which is not supported by its parser.



More information about the Python-ideas mailing list