> Awesome Kevin. That solution is sexy. I don't even need the java
> library anymore.
Note, however, that this can return (or do!) near anything, because it
accepts any Clojure syntax.
user=> (read-string "\"foo\"")
"foo" ; a string
user=> (read-string "(1.1)")
(1.1) ; a list containing a float
user=> (read-string "foo")
user/foo ; an interned symbol
including executing arbitrary code, unless you bind *read-eval*:
user=> (read-string "#=(println \"Oof\")")
Oof ; this gets printed. It could do much worse.
nil
In short... use the reader when you want to handle Clojure syntax. If
you want to convert a string to a decimal, do it properly. You'll get
useful exceptions, prevent bad input, and avoid inadvertent attack
vectors.
There's no "needing the Java library" -- you always have the core Java
classes available, including Double and BigDecimal.
HTH,
-R