How does one parse numbers in Joker? In Clojure, I’d call a Java constructor for a numeric type, but that approach obviously won’t work in Joker.
Joker really needs a much larger standard library, and I hope to provide (relatively soon) a version that wraps at least half of Go's std
library (to address issues like this) -- not yet up to that %, but slow progress is being made.
In the meantime, here ya go:
user=> (with-in-str "123" (read))
123
user=>
(Wrap in try
as needed.)If you want to be ahead of the not-even-bleeding-yet-it's-such-a-fresh-cut edge, you could try my fork of Joker (see https://github.com/jcburley/joker) and use something like this:
user=> (sort (keys (ns-publics 'go.std.strconv)))
(Atoi CanBackquote FormatBool FormatInt Itoa ParseBool ParseInt ParseUint Quote QuoteToASCII QuoteToGraphic Unquote)
user=> (doc go.std.strconv/Atoi)
-------------------------
go.std.strconv/Atoi
([_s])
Atoi returns the result of ParseInt(s, 10, 0) converted to type int.
Go input arguments: (s string)
Go return type: (int, error)
Joker input arguments: [^String s]
Joker return type: [Int Error]
nil
user=>
(go.std.strconv/Atoi "123")
[123 nil]
user=>
I'd like to think that'd be a lot faster, but have not measured it yet!read
or read-string
will work just fine for my purposes. Thanks!