babashka / sci

Configurable Clojure/Script interpreter suitable for scripting and Clojure DSLs
Eclipse Public License 1.0
1.23k stars 88 forks source link

Support IPrintWithWriter (CLJS) #794

Closed borkdude closed 2 years ago

borkdude commented 2 years ago

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:

Also see https://github.com/babashka/sci/issues/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 commented 2 years ago

@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.