I am trying to read data (which is actually an array) in Lisp from a text file.
I tried to use with-open-file and read-line stuff but could not achieve my goal. What I am looking for is equivalent to doing data=load('filename.txt') in MATLAB, so that I get an array called data which has loaded the whole information in filename.txt.
The text file will be in a format like
1.0 2.0 3.0 ...
1.5 2.5 3.5 ...
2.0 3.0 4.0 ...
.....
The size may also vary. Thanks a lot in advance.
The basic way to do that is to use
with-open-filefor getting the input stream,read-linein aloopto get the lines,split-sequence(from the library of the same name) to split it into fields, andparse-number(from the library of the same name) to transform the strings into numbers. All libraries mentioned are available from Quicklisp.EDIT: Just to get you started, this is a simple version without validation:
You should add some checks and think about what you want to get in case they are not fulfilled: