The 2htdp/batch-io library contains the useful read-csv-file procedure for reading a CSV file into a list. It takes a filename as its argument. Unfortunately, it does not take a string containing CSV as its argument. Suppose I have a CSV in a string variable and I want to use read-csv-file to parse it. Is there a way to avoid saving the CSV to a file just to be able to parse the CSV?
The documentation says:
reads the standard input device (until closed) or the content of file f and produces it as a list of lists of comma-separated values.
The standard input feature could probably be exploited to achieve this, but I don't know how to proceed with this idea.
I found a way to make
read-csv-fileread from a string instead:This works by changing the standard input to be the CSV string.
@Ryan Schaefer's answer about
simulate-fileis great, but I feel a bit uncomfortable with using functionality that is still "under development" and not properly documented. Assimulate-file's documentation says: