Giter Site home page Giter Site logo

non-global-extensibility about puget HOT 10 CLOSED

greglook avatar greglook commented on August 17, 2024
non-global-extensibility

from puget.

Comments (10)

gfredericks avatar gfredericks commented on August 17, 2024

I will probably be trying this out myself for a library I'm writing, so I'll point to some code once I have it.

from puget.

greglook avatar greglook commented on August 17, 2024

Yeah, I've run into this too. I think that Fressian's model might be better for this - you explicitly specify a map of write handlers which are used to serialize, and on the other side you provide a map of read handlers from tags to reader functions.

from puget.

gfredericks avatar gfredericks commented on August 17, 2024

ah right, so a map whose keys are classes?

from puget.

gfredericks avatar gfredericks commented on August 17, 2024

how should that interact with the builtin functionality? e.g. what happens if I put clojure.lang.PersistentVector in the map?

from puget.

greglook avatar greglook commented on August 17, 2024

I think you'd want the explicit handlers to override builtin serialization. Fressian also has a nice lookup-by-inheritance feature so you can use superclasses or interfaces to catch all the descendant types.

from puget.

gfredericks avatar gfredericks commented on August 17, 2024

okay this sounds cool. incidentally if I end up doing this it will be for https://github.com/gfredericks/webscale

from puget.

gfredericks avatar gfredericks commented on August 17, 2024

Alright, I think I got it working here.

Some design choices I had to make:

  • name/format for the additional option: :class-lookup is a map from classes to (fn [value] {:tag ... :form ...})
  • where to put the class/interface lookup algorithm: a new namespace puget.class-lookup
  • how to cache results so we don't walk the inheritance hierarchy all the time: add a memoized function to *options* in the with-options macro
  • how to incorporate it into the format-doc multimethod: check the class-lookup before the protocol, and dispatch to a modified version of the ::tagged-literal impl; this entails looking up the impl twice, but I don't think that's much different from what the protocol codepath is doing anyhow

Let me know how this sounds and I can add docs and make a PR.

from puget.

gfredericks avatar gfredericks commented on August 17, 2024

(edited previous comment to point to a slightly different commit)

from puget.

gfredericks avatar gfredericks commented on August 17, 2024

oh and tests. also I would add tests.

from puget.

greglook avatar greglook commented on August 17, 2024

Released 0.9.0 with support for custom print handlers.

from puget.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.