main.nv
· 5.6 KiB · Text
Sin formato
Playground
|_| low-level clear action
I seriously need to write a generator for these...
|clearing (@table id), @table id|
|clearing (@table id)|
|clearing (@table row), @table row|
|clearing (@table row)|
|clearing (pretty print rows iterator), pretty print rows iterator|
|clearing (pretty print rows iterator)|
|clearing (print number iterator), print number iterator|
|clearing (print number iterator)|
|_| high-level clear action
|clear (@table id)|
, clearing (@table id):9007199254740991
|clear (@table row)|
, clearing (@table row):9007199254740991
|clear (pretty print rows iterator)|
, clearing (pretty print rows iterator):9007199254740991
|clear (print number iterator)|
, clearing (print number iterator):9007199254740991
|_| low-level restore from temporary storage action
|restoring (pretty print row index), temporary (pretty print row index)|
, pretty print row index
|restoring (pretty print row index)|
|_| low-level move action
|moving (@table size) to (pretty print rows iterator), @table size|
, pretty print rows iterator
|moving (@table size) to (pretty print rows iterator)|
|_| low-level copy action
|copying (pretty print row index) to (@table row), pretty print row index|
, copying (pretty print row index) to (@table row)
, temporary (pretty print row index)
, @table row
|copying (pretty print row index) to (@table row)|
, restoring (pretty print row index)
|_| high-level move action
|move (@table size) to (pretty print rows iterator)|
, clear (pretty print rows iterator)
, moving (@table size) to (pretty print rows iterator):9007199254740991
|move (@table size) to (print number iterator)|
, clear (print number iterator)
, moving (@table size) to (print number iterator):9007199254740991
|_| high-level copy action
|copy (pretty print row index) to (@table row)|
, clear (@table row)
, copying (pretty print row index) to (@table row):9007199254740991
|_| Define our tables
|#table, singles|
, 1st
|#table, doubles|
, 1st, 2nd
|#table, triples|
, 1st, 2nd, 3rd
|_| Operations to select a table by id
Hand written to show a general pattern for this
|set (@table id) to (singles) table| @table id:1
|set (@table id) to (doubles) table| @table id:2
|set (@table id) to (triples) table| @table id:3
|select (singles) table|
, clear (@table id)
, set (@table id) to (singles) table
|select (doubles) table|
, clear (@table id)
, set (@table id) to (doubles) table
|select (triples) table|
, clear (@table id)
, set (@table id) to (triples) table
|_| ports for reading the size of a table
|#port, on get table size
, needs, @get table size
, reads, @table id|
, @table size, @no such table
|#port body, on get table size, lua|
if self.tables[table_id] then
counters["@table size"] = #self.tables[table_id]
else
counters["@no such table"] = 1
end
|_| Read data from the command line and pump it into a table.
|#port, on read singles, needs, @read singles|
|#port body, on read singles, lua|
local input = io.read("*a")
for left, right in input:gmatch("(%d+)") do
self.tables:push_row("singles",
{ ["1st"] = tonumber(left) or 0
}
)
end
|#port, on read doubles, needs, @read doubles|
|#port body, on read doubles, lua|
local input = io.read("*a")
for left, right in input:gmatch("(%d+),%s*(%d+)") do
self.tables:push_row("doubles",
{ ["1st"] = tonumber(left) or 0
, ["2nd"] = tonumber(right) or 0
}
)
end
|#port, on read triples, needs, @read triples|
|#port body, on read triples, lua|
local input = io.read("*a")
for left, right in input:gmatch("(%d+),%s*(%d+),%s*(%d+)") do
self.tables:push_row("triples",
{ ["1st"] = tonumber(left) or 0
, ["2nd"] = tonumber(right) or 0
, ["3rd"] = tonumber(right) or 0
}
)
end
|_| A generic operations over a table
|#port, on pretty print row
, needs, @pretty print row,
, reads, @table id, @table row|
|#port body, on pretty print row, lua|
local rows = self.tables[table_id]
local row = rows[table_row]
io.write(rows.name .. " #" .. tostring(table_row) .. ": ")
local mapping = self.tables.mappings[rows.name]
local assembled_row = {}
for key, index in pairs(mapping) do
assembled_row[key] = row[index]
end
pprint(assembled_row)
|_| loop to pretty print the rows of any table
|pretty print rows|
, clear (@table row)
, get table size for (pretty print rows)
, pretty printing rows
|get table size for (pretty print rows)|
, @get table size
, move (@table size) to (pretty print rows iterator)
|pretty printing rows, pretty print rows iterator|
, pretty print row index
, copy (pretty print row index) to (@table row)
, pretty print row
, next pretty print rows
|pretty printing rows|
|pretty print row|
, @pretty print row
|next pretty print rows|
, pretty printing rows
|pretty print row index|
|| 1st: read singles
, 2nd: pretty print singles
, 3rd: read doubles
, 4th: pretty print doubles
, 5th: read triples
, 6th: pretty print triples
|1st: read singles|
, @read singles
|2nd: pretty print singles|
, select (singles) table
, pretty print rows
|3rd: read doubles|
, @read doubles
|4th: pretty print doubles|
, select (doubles) table
, pretty print rows
|5th: read triples|
, @read triples
|6th: pretty print triples|
, select (triples) table
, pretty print rows
| 1 | |_| low-level clear action |
| 2 | I seriously need to write a generator for these... |
| 3 | |clearing (@table id), @table id| |
| 4 | |clearing (@table id)| |
| 5 | |
| 6 | |clearing (@table row), @table row| |
| 7 | |clearing (@table row)| |
| 8 | |
| 9 | |clearing (pretty print rows iterator), pretty print rows iterator| |
| 10 | |clearing (pretty print rows iterator)| |
| 11 | |
| 12 | |clearing (print number iterator), print number iterator| |
| 13 | |clearing (print number iterator)| |
| 14 | |
| 15 | |
| 16 | |_| high-level clear action |
| 17 | |clear (@table id)| |
| 18 | , clearing (@table id):9007199254740991 |
| 19 | |
| 20 | |clear (@table row)| |
| 21 | , clearing (@table row):9007199254740991 |
| 22 | |
| 23 | |clear (pretty print rows iterator)| |
| 24 | , clearing (pretty print rows iterator):9007199254740991 |
| 25 | |
| 26 | |clear (print number iterator)| |
| 27 | , clearing (print number iterator):9007199254740991 |
| 28 | |
| 29 | |
| 30 | |
| 31 | |_| low-level restore from temporary storage action |
| 32 | |restoring (pretty print row index), temporary (pretty print row index)| |
| 33 | , pretty print row index |
| 34 | |restoring (pretty print row index)| |
| 35 | |
| 36 | |
| 37 | |
| 38 | |_| low-level move action |
| 39 | |moving (@table size) to (pretty print rows iterator), @table size| |
| 40 | , pretty print rows iterator |
| 41 | |moving (@table size) to (pretty print rows iterator)| |
| 42 | |
| 43 | |
| 44 | |
| 45 | |_| low-level copy action |
| 46 | |copying (pretty print row index) to (@table row), pretty print row index| |
| 47 | , copying (pretty print row index) to (@table row) |
| 48 | , temporary (pretty print row index) |
| 49 | , @table row |
| 50 | |
| 51 | |copying (pretty print row index) to (@table row)| |
| 52 | , restoring (pretty print row index) |
| 53 | |
| 54 | |
| 55 | |
| 56 | |_| high-level move action |
| 57 | |move (@table size) to (pretty print rows iterator)| |
| 58 | , clear (pretty print rows iterator) |
| 59 | , moving (@table size) to (pretty print rows iterator):9007199254740991 |
| 60 | |
| 61 | |move (@table size) to (print number iterator)| |
| 62 | , clear (print number iterator) |
| 63 | , moving (@table size) to (print number iterator):9007199254740991 |
| 64 | |
| 65 | |
| 66 | |_| high-level copy action |
| 67 | |copy (pretty print row index) to (@table row)| |
| 68 | , clear (@table row) |
| 69 | , copying (pretty print row index) to (@table row):9007199254740991 |
| 70 | |
| 71 | |
| 72 | |
| 73 | |_| Define our tables |
| 74 | |#table, singles| |
| 75 | , 1st |
| 76 | |
| 77 | |#table, doubles| |
| 78 | , 1st, 2nd |
| 79 | |
| 80 | |#table, triples| |
| 81 | , 1st, 2nd, 3rd |
| 82 | |
| 83 | |
| 84 | |
| 85 | |_| Operations to select a table by id |
| 86 | Hand written to show a general pattern for this |
| 87 | |set (@table id) to (singles) table| @table id:1 |
| 88 | |set (@table id) to (doubles) table| @table id:2 |
| 89 | |set (@table id) to (triples) table| @table id:3 |
| 90 | |
| 91 | |select (singles) table| |
| 92 | , clear (@table id) |
| 93 | , set (@table id) to (singles) table |
| 94 | |
| 95 | |select (doubles) table| |
| 96 | , clear (@table id) |
| 97 | , set (@table id) to (doubles) table |
| 98 | |
| 99 | |select (triples) table| |
| 100 | , clear (@table id) |
| 101 | , set (@table id) to (triples) table |
| 102 | |
| 103 | |
| 104 | |
| 105 | |_| ports for reading the size of a table |
| 106 | |#port, on get table size |
| 107 | , needs, @get table size |
| 108 | , reads, @table id| |
| 109 | , @table size, @no such table |
| 110 | |#port body, on get table size, lua| |
| 111 | if self.tables[table_id] then |
| 112 | counters["@table size"] = #self.tables[table_id] |
| 113 | else |
| 114 | counters["@no such table"] = 1 |
| 115 | end |
| 116 | |
| 117 | |
| 118 | |_| Read data from the command line and pump it into a table. |
| 119 | |#port, on read singles, needs, @read singles| |
| 120 | |#port body, on read singles, lua| |
| 121 | local input = io.read("*a") |
| 122 | for left, right in input:gmatch("(%d+)") do |
| 123 | self.tables:push_row("singles", |
| 124 | { ["1st"] = tonumber(left) or 0 |
| 125 | } |
| 126 | ) |
| 127 | end |
| 128 | |
| 129 | |#port, on read doubles, needs, @read doubles| |
| 130 | |#port body, on read doubles, lua| |
| 131 | local input = io.read("*a") |
| 132 | for left, right in input:gmatch("(%d+),%s*(%d+)") do |
| 133 | self.tables:push_row("doubles", |
| 134 | { ["1st"] = tonumber(left) or 0 |
| 135 | , ["2nd"] = tonumber(right) or 0 |
| 136 | } |
| 137 | ) |
| 138 | end |
| 139 | |
| 140 | |#port, on read triples, needs, @read triples| |
| 141 | |#port body, on read triples, lua| |
| 142 | local input = io.read("*a") |
| 143 | for left, right in input:gmatch("(%d+),%s*(%d+),%s*(%d+)") do |
| 144 | self.tables:push_row("triples", |
| 145 | { ["1st"] = tonumber(left) or 0 |
| 146 | , ["2nd"] = tonumber(right) or 0 |
| 147 | , ["3rd"] = tonumber(right) or 0 |
| 148 | } |
| 149 | ) |
| 150 | end |
| 151 | |
| 152 | |
| 153 | |_| A generic operations over a table |
| 154 | |#port, on pretty print row |
| 155 | , needs, @pretty print row, |
| 156 | , reads, @table id, @table row| |
| 157 | |#port body, on pretty print row, lua| |
| 158 | local rows = self.tables[table_id] |
| 159 | local row = rows[table_row] |
| 160 | io.write(rows.name .. " #" .. tostring(table_row) .. ": ") |
| 161 | local mapping = self.tables.mappings[rows.name] |
| 162 | local assembled_row = {} |
| 163 | for key, index in pairs(mapping) do |
| 164 | assembled_row[key] = row[index] |
| 165 | end |
| 166 | pprint(assembled_row) |
| 167 | |
| 168 | |
| 169 | |
| 170 | |_| loop to pretty print the rows of any table |
| 171 | |pretty print rows| |
| 172 | , clear (@table row) |
| 173 | , get table size for (pretty print rows) |
| 174 | , pretty printing rows |
| 175 | |
| 176 | |get table size for (pretty print rows)| |
| 177 | , @get table size |
| 178 | , move (@table size) to (pretty print rows iterator) |
| 179 | |
| 180 | |pretty printing rows, pretty print rows iterator| |
| 181 | , pretty print row index |
| 182 | , copy (pretty print row index) to (@table row) |
| 183 | , pretty print row |
| 184 | , next pretty print rows |
| 185 | |
| 186 | |pretty printing rows| |
| 187 | |
| 188 | |pretty print row| |
| 189 | , @pretty print row |
| 190 | |
| 191 | |next pretty print rows| |
| 192 | , pretty printing rows |
| 193 | |
| 194 | |pretty print row index| |
| 195 | |
| 196 | |
| 197 | || 1st: read singles |
| 198 | , 2nd: pretty print singles |
| 199 | , 3rd: read doubles |
| 200 | , 4th: pretty print doubles |
| 201 | , 5th: read triples |
| 202 | , 6th: pretty print triples |
| 203 | |
| 204 | |1st: read singles| |
| 205 | , @read singles |
| 206 | |
| 207 | |2nd: pretty print singles| |
| 208 | , select (singles) table |
| 209 | , pretty print rows |
| 210 | |
| 211 | |3rd: read doubles| |
| 212 | , @read doubles |
| 213 | |
| 214 | |4th: pretty print doubles| |
| 215 | , select (doubles) table |
| 216 | , pretty print rows |
| 217 | |
| 218 | |5th: read triples| |
| 219 | , @read triples |
| 220 | |
| 221 | |6th: pretty print triples| |
| 222 | , select (triples) table |
| 223 | , pretty print rows |
| 224 |
output.txt
· 534 B · Text
Sin formato
Playground
123
234
25
singles #1: {
['1st'] = 123
}
singles #2: {
['1st'] = 234
}
singles #3: {
['1st'] = 25
}
123, 234
43, 192
392, 123
doubles #1: {
['1st'] = 123,
['2nd'] = 234
}
doubles #2: {
['1st'] = 43,
['2nd'] = 192
}
doubles #3: {
['1st'] = 392,
['2nd'] = 123
}
123, 439, 192
203, 291, 398
192, 43, 212
triples #1: {
['1st'] = 123,
['2nd'] = 439,
['3rd'] = 439
}
triples #2: {
['1st'] = 203,
['2nd'] = 291,
['3rd'] = 291
}
triples #3: {
['1st'] = 192,
['2nd'] = 43,
['3rd'] = 43
}
| 1 | 123 |
| 2 | 234 |
| 3 | 25 |
| 4 | singles #1: { |
| 5 | ['1st'] = 123 |
| 6 | } |
| 7 | singles #2: { |
| 8 | ['1st'] = 234 |
| 9 | } |
| 10 | singles #3: { |
| 11 | ['1st'] = 25 |
| 12 | } |
| 13 | 123, 234 |
| 14 | 43, 192 |
| 15 | 392, 123 |
| 16 | doubles #1: { |
| 17 | ['1st'] = 123, |
| 18 | ['2nd'] = 234 |
| 19 | } |
| 20 | doubles #2: { |
| 21 | ['1st'] = 43, |
| 22 | ['2nd'] = 192 |
| 23 | } |
| 24 | doubles #3: { |
| 25 | ['1st'] = 392, |
| 26 | ['2nd'] = 123 |
| 27 | } |
| 28 | 123, 439, 192 |
| 29 | 203, 291, 398 |
| 30 | 192, 43, 212 |
| 31 | triples #1: { |
| 32 | ['1st'] = 123, |
| 33 | ['2nd'] = 439, |
| 34 | ['3rd'] = 439 |
| 35 | } |
| 36 | triples #2: { |
| 37 | ['1st'] = 203, |
| 38 | ['2nd'] = 291, |
| 39 | ['3rd'] = 291 |
| 40 | } |
| 41 | triples #3: { |
| 42 | ['1st'] = 192, |
| 43 | ['2nd'] = 43, |
| 44 | ['3rd'] = 43 |
| 45 | } |