Fork me on GitHub
#clojurescript
<
2024-01-27
>
vraid16:01:36

In clojure i can use java interop to parse integers and floats from strings, but what's the canonical way to do it in clojurescript?

p-himik16:01:57

You don't need interop for that, neither in CLJ nor in CLJS - there are built-in parse-long and parse-double.

p-himik16:01:50

No. Unless you're dealing specifically with interop, Clojure's numbers are either longs or doubles.

p-himik16:01:04

And CLJS doesn't have ints at all, like JS itself.

vraid16:01:24

Oh, okay. That's an interesting design decision

vraid16:01:47

I don't care that much for the internals of the number though, i just want to make sure that it's mathematically an integer. I'll see if i can work it out with parsing and integer? then

p-himik16:01:30

> i just want to make sure that it's mathematically an integer Then parse-long is what you need, no?

p-himik16:01:37

A long is an integer number.

vraid16:01:35

Ah, of course. I was thinking of single for some reason. That should work, thanks!

p-himik16:01:45

> That's an interesting design decision In practice, most of the problems don't require differentiating between integer types. So much so that e.g. Python went further and combined them all together into an unbound int. The differentiation might be needed to make something more efficient in some way. And most of the time you can do it just fine in Clojure.

vraid16:01:01

My mind is a bit slow today, and for a minute there i thought longs were floats, hence my comment

vraid16:01:16

I should have no excuse as i have worked with C a lot 🙂

p-himik16:01:00

Ah, gotcha.