speech impediment wrote:Code: Select all
(defvar *stream* (open "C:\\yada\\table.csv"))
(substitute #\space #\, (read-line *stream*))
(edited for clarity -- the initial indentation fooled me for a while.
speech impediment wrote:I probably should use WITH-OPEN-FILE instead of OPEN, but I couldn't read the next line in the csv file.
With-open-file is just a macro that closes the file when the macro body completes (try macroexpanding it to see how it works). It is perfectly fine to close the file manually by yourself.
speech impediment wrote: I know I don't have an iterative array making part yet, but I am stuck at reading the entire string separated by spaces. I used READ-FROM-STRING (and a few combination of its keywords), but it seems to stop at the first space:
Yes. Read-from-string just reads one form (symbol, number, string, parenthesized expression, etc.) at a time. You will have to use it in a loop to get everything out of the line.
speech impediment wrote:Code: Select all
(read-from-string (substitute #\space #\, (read-line *stream*))
;Sample result:
|2010-09-27|
10
I understand the first element isn't really a number, but I forgot what those bars mean: |...|
I also tried to substitute the quotation marks but it seems that Lisp doesn't understand this: #\"
This "substitute #\space #\," should work as long as your values don't contain commas or spaces (i.e. no string values). The vertical bars mark symbol names containing nonstandard characters (mixed upper and lower case, spaces, etc.). The quotation marks are added by the printer to make strings usable by READ -- they don't actually exist in your sample data.