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

Custom formatters (print-method) don't work via Java-style interop #1493

Open
jakub-stastny opened this issue Feb 13, 2023 · 2 comments
Open
Projects

Comments

@jakub-stastny
Copy link

[ To keep development of this project going, consider sponsoring. If you are
already a sponsor, thank you! ]

version

babashka v1.1.172

platform

Current macOS

problem

print-method seems broken.

repro

Screenshot 2023-02-13 at 15 22 34

Screenshot 2023-02-13 at 15 19 37

expected behavior

Clojure output in the screenshot is the expected behaviour.

@jakub-stastny
Copy link
Author

jakub-stastny commented Feb 13, 2023

(defprotocol Version (stringify [this] "Get string representation"))
(deftype QID [a b c d] Version (stringify [_] "test"))
(defmethod print-method QID [object out]
  (.write out (stringify object)))

(println "HERE")
(printin (.stringify (QID. 4 0 0 1)))
(println (QID. 4 0 0 1))
(defprotocol Version (toString [this] "Get string representation"))
(deftype QID [a b c d] Version (toString [-] "test"))

(println "HERE")
(println (. toString (QID. 4 0 0 1)))
(println (QID. 4 0 0 1))

@borkdude
Copy link
Collaborator

So (stringify (QID. 4 0 0 1)) does work and so does (str (QID. 4 0 0 1)) which are probably more idiomatic ways of doing the same as (.stringify ..) and (.toString..). But nonetheless it's something to look into and see if this difference can be fixed.

@borkdude borkdude changed the title Custom formatters (print-method) don't work Custom formatters (print-method) don't work via Java-style interop Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Babashka
Awaiting triage
Development

No branches or pull requests

2 participants