Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IPrintWithWriter (CLJS) #794

Closed
borkdude opened this issue Aug 30, 2022 · 1 comment
Closed

Support IPrintWithWriter (CLJS) #794

borkdude opened this issue Aug 30, 2022 · 1 comment

Comments

@borkdude
Copy link
Collaborator

borkdude commented Aug 30, 2022

Similar to print-method.

Some notes:

  1. SCI implements protocols methods as multimethods
  2. In JVM print-method is not included by default, it needs access to the host print-method multimethod
  3. SCI records are based on one Clojure / CLJS record type which defers to a runtime SCI type. When implementing print-method for a SCI records, some state is mutated which affects the general Clojure / CLJS print-method for the general record type which dispatches on the SCI type.
  4. To let users implement IPrintWithWriter in general (not records), we could do two things:
  • Have a multi-method counterpart which defers to the protocol (this is done for e.g. IDeref in SCI). This comes with performance overhead for printing though.
  • Mutate the IPrintWithWriter CLJS protocol directly (given access to the host, or, presence of this protocol in the SCI config)
  1. But since SCI records all share one CLJS record type, 4 isn't sufficient, so we need to defer to some indirection anyway which can be mutated given the SCI type of the record.

Also see #639

It seems, just for SCI records, we don't need to implement IPrintWithWriter for all use cases, so maybe starting with 5 and working our way back is the best approach.

@borkdude
Copy link
Collaborator Author

borkdude commented Sep 8, 2022

@grzm I pushed something to printwithwriter (not ready).

If we can get SCI to put (-pr-writer ..) functions as metadata on the record var under :sci.impl/print-method then it should work.

So we should add some hard-coded check of IPrintWithWriter implementations and then handle that separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant