I have a file which has an bi-dimensional array in each line. I'm having trouble finding a way of parsing the file into actual arrays and them putting them in a list.
the file looks like this, the arrays are in different lines, even though it does not seem to:
You just open the file for reading using with-open-file
and then use the function read
as often as you would like or as often as there are arrays. Each read
returns an array. Using loop
you can collect them into a list.
Basically something like this:
(with-open-file (s filename)
(let ((*read-eval* nil))
(loop with eof = '#:eof
for object = (read s nil eof)
until (eq object eof)
collect object)))
Note also that it does not matter whether each array is on its own line. It would still work if they are on one line. A newline between expressions is just whitespace for the Lisp reader.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With