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

Strategy to print goog.math/Long #91

Open
prabhjots opened this issue Sep 24, 2024 · 1 comment
Open

Strategy to print goog.math/Long #91

prabhjots opened this issue Sep 24, 2024 · 1 comment

Comments

@prabhjots
Copy link

goog.math/Long is not showing up very well

#?(:cljs
   (let [x (goog.math/Long.fromString "123")]
     (with-out-str (fipp/pprint {:test x} {:width 120}))))

It evaluates to the following

"{:test #object[#object[Long]]}\n"

Problem gets fixed by using the IEdn protocol

#?(:cljs
   (extend-protocol IEdn
     goog.math/Long
     (-edn [x]
       (js/Number (.toString ^goog.math/Long x)))))

Is using the IEdn protocol is the right approach for this problem. If yes then please consider documenting the IEdn protocol in the readme.

@brandonbloom
Copy link
Owner

brandonbloom commented Sep 27, 2024

Yes, IEdn is the right way to do this. I should probably document it.

However, I think you may want to avoid losing precision by doing something like this:

#?(:cljs
   (extend-protocol IEdn
     goog.math/Long
     (-edn [x]
       (tagged-literal 'goog/long (.toString ^goog.math/Long x)))))

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

2 participants