Fork me on GitHub
#clojure-dev
<
2021-12-09
>
seancorfield23:12:49

Just sort of shot myself in the foot with Clojure Alpha 3 because of this subtle difference:

dev=> (.longValue (.parse (java.text.NumberFormat/getInstance) "42#"))
42
dev=> (parse-long "42#")
nil
I had no idea that NumberFormat's parse method would ignore trailing bad characters. So parse-long has the correct behavior from my point of view but it uncovered a rather unpleasant bug lurking in one of our web forms 😕

borkdude23:12:21

I also got an unexpected nil in some Advent of Code input where there was a trailing newline: (parse-long "1\n")which manifested as an NPE when something numeric was expected.

seancorfield23:12:26

I would have been equally surprised by dev=> (.longValue (.parse (java.text.NumberFormat/getInstance) "42\n")) ;=> 42 🙂

borkdude23:12:57

yeah, I don't have a clear preference here, I'm fine with throwing or nil, eventually it will get into your muscle memory