▲ | kazinator 3 hours ago | |
Common Lisp has this (and other dialects that imitate the Circle Notation; I think Scheme has it now, Emacs Lisp, TXR lisp, ): E.g.
encodes
where the two (a b) occurrences are one object. It can express circular structures:
encodes an infinite circular list
The object to be duplicated is prefixed with #<decimal-integer>=. This associates the object with the integer. The integer is later referenced as #<decimal-integer># to replicate it.The thing is, you don't see a lot of this in human-written files, whether they are source code or data. This is not the primary way that Lisp systems use for specifying replicated data in configurations, let alone code. Substructure sharing occurs whether you use the notation or not due to interned symbols. (Plus compilers can deduplicate strings and such.) In (a a a) there is only one object a, a symbol. If you feed the implementation circular source code though, ANSI CL says the behavior is undefined. Some interpreters can handle it under the right circumstances. In particular ones that don't try to do a full macro-expanding code walk before running the code. Compilers, not so much. |