Clojure - Issues with solution templates and `read`

Hello folks,

I noticed many of the Clojure boilerplate starting points use the read function to try and pull in values. Take a look at the docs for the function: https://clojuredocs.org/clojure.core/read

This function pulls in data, treating it as Clojure language symbols; this means that it will correctly interpret numbers, but will behave strangely around anything more complex. Strings, for example, come out as unique symbols, meaning that calling read on the same string would give back two different symbols that can’t be compared properly, leading to all sorts of unexpected behaviour until the cause is weaseled out.

It may be helpful to find an alternative, such as pulling in Java’s Scanner class to read values (which should be perfectly acceptable Clojure code).

1 Like