parse-long and parse-double are Clojure functions. They return the number, or nil when the text is not a number.
parse-long
parse-double
(println (parse-long "42")) (println (parse-long "nope")) (println (parse-double "3.5"))
The Go parsers return a vector of the number and an error. Atoi parses an integer. ParseFloat takes the bit size as well.
Atoi
ParseFloat
(let [[n err] (strconv.Atoi "256")] (println n (nil? err))) (let [[n err] (strconv.ParseFloat "1.25" 64)] (println n (nil? err)))
A failed parse-long is nil, not an exception.
$ glj number-parsing.glj 42 nil 3.5 256 true 1.25 true
Next example: URL Parsing.
A hands-on tour in the style of Go by Example. Glojure is a Clojure interpreter hosted on Go.