From googling around, I found that using while
loops or using variables is discouraged.
Now I implemented a very simple algorithm that will read characters from an inputstream and parse accordingly: if input is 10:abcdefghej
it will parse out 10
then read next 10 bytes after the colon.
The thing I am kinda lost with is how I can refactor this so it does not rely on variables.
(defn decode-string [input-stream indicator]
(with-local-vars [length (str (char indicator) )
delimiter (.read input-stream )
string (str "")
counter 0 ]
(while (not(= (var-get delimiter) 58 ))
(var-set length (str (var-get length) (char (var-get delimiter)) ))
(var-set delimiter (.read input-stream )))
(var-set length (new BigInteger (var-get length)) )
(var-set counter (var-get length))
(while (not(zero? (var-get counter) ))
(var-set string (str (var-get string) (char (.read input-stream )) ))
(var-set counter (dec (var-get counter))))
(var-get string)))
Also, I understand that the only way to declare variables is using the with-local-vars
keyword. Isn't it kind of unpractical to define all the variables in one block at the beginning, or am I missing some crucial point?