Open jkroso opened 8 years ago
The Common Lisp reader lets you tag anything with a number like #1=
and then reference it later with #1#
. It's neat, though I've used it maybe once ever. The arbitrary references make it easy to refer to other objects at any level of the hierarchy, and I suspect it minimizes the performance cost you mention, as the reader only needs to keep references to objects which were explicitly tagged.
But as cool as it is, I'm not sure I see the value for EDN, which says it's purely "for the conveyance of values", not objects. Doesn't cyclic data only make sense in the context of objects?
says it's purely "for the conveyance of values", not objects
Depends how you define values and objects I guess. But whenever one thing has a relationship with another thing the later usually has a relationship with the former too. e.g books have authors and authors have books.
One good syntax I have found for references is
# 1
,# 2
, etc.. where the number is the index of the object being referred to as it would be encountered when parsing the input stream of EDN. As far as I know this would otherwise be a syntax error so implementations are free to support it without potentially misinterpreting otherwise valid data.I know this comes at a performance cost so I don't expect it to become a compulsory part of the spec. It just took me a few goes to arrive at it so I thought I should put it out there to potentially save others some failed attempts.