I've successfully written a function that converts a space delimited string of integers to a vector of integers in Clojure but since I'm (very) new to functional languages I'm worried I'm still thinking too procedurally.
The function uses split to tokenize the string then iterates through the returned vector individually converting the tokens to integers before appending them to a new vector. I'm using read-string because the input is self provided and I'm not really concerned about safety.
(defn parser [myStr]
;;counter
(def i 0)
;;tokenizes string and returns vector of tokens
(def buffer (clojure.string/split myStr #"\s"))
;;reads vector of strings as integers then appends them to a new vector x
(def x (vector-of :int))
(while ( < i (count buffer))
(def x (conj x (read-string (nth buffer i))))
(def i (inc i)))
(println x))
My code works but I'm concerned that by changing states and iterating through the buffer vector that I'm cheating a bit and sticking to my procedural roots.
Is there a more elegant or functional way to solve this problem?