Reputation: 4043
I need to read a text file using Common Lisp. File must be read to list of lists. Each list in the list must consist of a line from file.
Now, I have done such code:
(with-open-file (in file)
(loop for line = (read-line in nil nil)
while line
collect (coerce line 'list)))
But, for example, the rusult looks as: ((#\0 #\0 #\0) (#\1 #\0 #\1)). But I need to have result without #\ characters: ((0 0 0) (1 0 1)). How to fix it?
Upvotes: 3
Views: 1013
Reputation: 60004
You are already converting the line to a list of characters; all you need to do is convert the characters to numbers:
(with-open-file (in file)
(loop for line = (read-line in nil nil)
while line
collect (map 'list #'digit-char-p line)))
You can also use (parse-integer (string c))
instead of digit-char-p
, but that seems an overkill.
Upvotes: 3