Home > Mobile >  extracting CSV data that needs to be re-read frequently?
extracting CSV data that needs to be re-read frequently?

Time:01-09

Most of the time when I read in CSV data I use local variables:


(defun do-something ()
...
  (let ((thing (read-csv #P"~/Desktop/file.csv")))

   .... do stuff with thing))

This works. However, some of my functions are becoming quite large and messy. So I tried putting the function to read in data in a special variable:


(defparameter *file* (read-csv #P"~/Desktop/file.csv"))

But when I use the *file* variable, it doesn't update with the new file.csv.

Is there a way to force refresh or maybe a better way of extracting CSV data in real time?

CodePudding user response:

As a variable, *file* is initialized from the result of read-csv function. So unless you setf *file* again from read-csv it will not update.

If the path doesn't change you could wrap read-csv into another function like:

(defun retrieve-csv-data ()
  (read-csv #P"~/Desktop/file.csv"))

And use that where ever you need the csv data.

  • Related