DrRacket generated 3 useful files from 1 data file
D.R.Y. for Teachers
If it wasn't for SJIS (or some sort of MS Windows Encoding Page) troubles, this script would probably be useful and reliable. I'm fudging the possible encoding issues by, using “key” and “value” as backups when assoc
doesn't find what it should in an associative list (alist, als). Playing with Scheme/Racket gives you the confidence to deal with any problem, if some detail isn't working, just throw in an if
or cond
statement, and maybe the results will help you figure out where the trouble is. DrRacket is great for showing where errors are, it even produces bright red lines that trace the errors for you...
There is a pattern, where I develop the script to generate useful pages to process one data file and then adapt it to handle several files in a directory. After the script seems to work for one data file, I get all the define
definitions used to transform data (not those used to make functions) from the original file, and put those definitions into a let*
expression (or clause) within a procedure that is used with for-each
to go through a list of data files. Some definitions remain global, but all the definitions that rely on the data file go into a let*
clause.
This code is re-working of earlier code (fn:1) that, from one .csv data file generated three files: a racket data file, a browser page to print roll sheets, and a browser page to print a seating chart. To get code that will generate three useful files (a rkt data file, a roll sheet, and a seating chart) for each .csv data file in a directory, I just had to see what belongs in a let*
clause of the function that is mapped (with for-each
for the side-effects and the list-generation) over a list of file paths.
A typo(bug) that disturbed my flow made me appreciate first
and second
in place of car
and cadr
. I had build-path
errors that confused me for a while. when I moved the define cls-als
(class associative list: alist: als) into the let*
clause, I forgot the a
in cadr
. In place of a one-key one-value associative list, I ended up with, not a string, but a long list as the value. Without the string, I could build paths for file-generation. I imagine using first
and second
could make it easier to spot a mistake like that. But cddr
is probably still useful instead of (rest (rest ...
.
There is another bug, where the first seat is taken up by the keys for associative list, or what could be viewed as column headers in a table of data. If there is time I'll see where in the chart-generation process to intervene, and get rid of the header intrusion. But the bug could be a feature, it can be nice to have an open table at the front of the room for returning papers, for set-up. With the Graded Direct Method teachers haul a lot of “realia” into the classroom, and tend to need tables and seats for demonstrations...