programlibs/Csv/demos/schema.xtl
A table's columns as named, typed variables: c_olumns< reads the schema when the program is compiled and writes a definition per column, so the program speaks of city and population, and their kinds are checked like any variable's. Run with "just demo Csv schema".
t : Box Char
t ← ᶜˢr̲ows @ i̲nclude< "cities.csv" ⍝ the data, built in from the file beside this program
i̲nclude< expands to
("city,country,population,area\nOslo,Norway,709037,454\n\"Washington, D.C.\",USA,678972,177\nLima,Peru,10092000,2672\nPerth,Australia,2192229,6418\nTurin,Italy,848885,130\n")Used in: city
city : Box Char
"city:text population:number area:number" ᶜˢc̲olumns< "t"
ᶜˢc̲olumns< expands to
city ← (1 d̲rop ((f̲irst t) i̲ndexOf e̲nclose "city") s̲elect₂ t) population ← n̲umbers d̲isclose '{ e̲nclose (d̲isclose ⍺) c̲at " " c̲at d̲isclose ⍵ } r̲/ (1 d̲rop ((f̲irst t) i̲ndexOf e̲nclose "population") s̲elect₂ t) area ← n̲umbers d̲isclose '{ e̲nclose (d̲isclose ⍺) c̲at " " c̲at d̲isclose ⍵ } r̲/ (1 d̲rop ((f̲irst t) i̲ndexOf e̲nclose "area") s̲elect₂ t)
population : Float
"city:text population:number area:number" ᶜˢc̲olumns< "t"
ᶜˢc̲olumns< expands to
city ← (1 d̲rop ((f̲irst t) i̲ndexOf e̲nclose "city") s̲elect₂ t) population ← n̲umbers d̲isclose '{ e̲nclose (d̲isclose ⍺) c̲at " " c̲at d̲isclose ⍵ } r̲/ (1 d̲rop ((f̲irst t) i̲ndexOf e̲nclose "population") s̲elect₂ t) area ← n̲umbers d̲isclose '{ e̲nclose (d̲isclose ⍺) c̲at " " c̲at d̲isclose ⍵ } r̲/ (1 d̲rop ((f̲irst t) i̲ndexOf e̲nclose "area") s̲elect₂ t)
area : Float
"city:text population:number area:number" ᶜˢc̲olumns< "t"
ᶜˢc̲olumns< expands to
city ← (1 d̲rop ((f̲irst t) i̲ndexOf e̲nclose "city") s̲elect₂ t) population ← n̲umbers d̲isclose '{ e̲nclose (d̲isclose ⍺) c̲at " " c̲at d̲isclose ⍵ } r̲/ (1 d̲rop ((f̲irst t) i̲ndexOf e̲nclose "population") s̲elect₂ t) area ← n̲umbers d̲isclose '{ e̲nclose (d̲isclose ⍺) c̲at " " c̲at d̲isclose ⍵ } r̲/ (1 d̲rop ((f̲irst t) i̲ndexOf e̲nclose "area") s̲elect₂ t)