bpsm / edn-java

a reader for extensible data notation
Eclipse Public License 1.0
100 stars 24 forks source link

edn-java should provide a way to write edn #1

Closed bpsm closed 11 years ago

mikera commented 11 years ago

A few thoughts on this:

mikera commented 11 years ago

Some more thoughts:

bpsm commented 11 years ago
mikera commented 11 years ago

Sounds good on all the above although I think the list/vector distinction will need to be tackled in order for round-tripping to work.

Using RandomAccessList is an interesting idea to differentiate lists and vectors. I think it should work. But then we'd need to either:

Let me know if you want a quick immutable list / vector implementation for this purpose, happy to provide.

bpsm commented 11 years ago

Depends on what you mean by "round trip". Data structure should be equal after parsing, writing out, and parsing again: parse(write(parse(text))) should equal parse(text).

This works in Java even if we don't preserve the distinction between () and [] because of the way that List.equals() is specified. But, naturally, it would be desirable to preserve the ()/[] distinction if possible.

I still find it's too early to begin implementing a writer. I still want to do some research on how this has been tackled in other projects. (JSON comes to mind). In particular, I'm looking for a good way to layer the implementation similarly to the Parser/Scanner layering. Still something I'm thinking about.

mikera commented 11 years ago

I guess as a user of the library I would expect a round trip to preserve the [] / () distinction. It would be very counter-intuitive for this not to be preserved!

bpsm commented 11 years ago

"I guess as a user of the library I would expect a round trip to preserve the [] / () distinction. It would be very counter-intuitive for this not to be preserved!"

Yes, that's true. It would feel like a second-class implementation otherwise, but that still means solving the problem of how to differentiate on the java side. So far, RandomAccess seems like the simplest idea.

mikera commented 11 years ago

My suggestion would be to make RandomAccess the default, but expose enough configurability that the user can change this if desired (this is the same functionality that will be needed anyway to provide tagged types).

If you are researching this, I would strongly recommend taking a look at how Kryo does it: they have a good system for allowing people to register custom serializers for different types that override the default serialization. Also their implementation is extremely fast/efficient.