say I want to have user input a matrix row by row. So I first ask for the size of the matrix, then I would like to ask for user input rows with prompt like "row 1" "row 2" etc.
The most trivial thing to do seems like to have a mutable vector and use somethinkg like doseq to mutate it.
But I'm curious if there are any more clojure way to do it.
My initial thought was to use for
or map
. But it is lazy so cannot print out the prompt.
so something like (map (fn [i] (do (printf "row %d \n" i) (read-line))) (range size))
will include prompt in the result list as well.
Then I thought I could use a macro to just produce something like
[((println "row i") (read-line))
((println "row i") (read-line))
((println "row i") (read-line)) ...]
Are there anyway I can do this without macro or mutable variable? Which way is better?