LISP - Convert string with array representation to array

I have a file with a two-dimensional array in each line. I am having trouble finding a way to parse a file in real arrays, and they put them in a list.

the file looks like this: arrays are on different lines, although this does not look like: matrix file

+5
source share
1 answer

You simply open the file for reading with-open-file , and then use the read function as often as you want, or as often as there are arrays. Each read returns an array. Using loop , you can put them in 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 if each array is on a separate line. It will work if they are on the same line. The new line between expressions is just a space for the Lisp reader.

+9
source

Source: https://habr.com/ru/post/1237648/


All Articles