In Clojure I am building a card game. Cards have a suit and a score.
{:suit 1 :score 9}
The cards are created using ranges, e.g. (range suitTotal), so the class of the values of :suit and :score is Long.
Players send command strings, e.g. “discard1.9” is a discard request.
Using a regex to parse this:
(re-seq #"[0-9]+" command)
results in String items “1” and “9”. A card created with these results would be
{:suit "1" :score "9"}
I would like this to compare as equal with the original card. At the moment I am using (Integer/parseInt) to convert the strings.
The suit value could be built from a different type, such as a keyword, but the score value is used as a number elsewhere.
A good approach would be to parse the strings as numbers and then use = to compare.
The advantage of this over read-string is this is more restricted. This won’t parse strings that look like clojure data-structures.