Over at clojuredocs.com they discussed why to not use read
or read-string
from untrusted sources. One way to use it might be as such:
=> (double (read-string "1.99"))
=> 1.99
=> (.Double "1.22")
=> IllegalArgumentException No matching field found: Double for class...
Which is useful if you need a double to store in the database. But what if the data is from user input? Suppose users want to enter their height in feet or something. How could we take the input string from a webpage and convert it to a double or other numeric value safely?
put the .
on the other side of Double
user> (Double. "1.22")
1.22
This calls the Double class's constructor which takes a string and produces a new double.
It's syntactic sugar for (new Double "1.22")