pretty print some data about australian cities
So, in my travels trying to work out how to write the pretty print table code (and yeah, I wrote my code from scratch, rather than copying anyone else's code), I found this page. Now, I did not even look at the code used there, but I did borrow the data in his table. Let's pretty print that with my new code:
-- first some knowledge:
sa: load pretty-print-table-of-australian-cities.sw
sa: dump
----------------------------------------
|context> => |context: pretty print table of Australian cities>
|city list> => |Adelaide> + |Brisbane> + |Darwin> + |Hobart> + |Melbourne> + |Perth> + |Sydney>
area |Adelaide> => |1295>
population |Adelaide> => |1158259>
annual-rainfall |Adelaide> => |mm: 600.5>
area |Brisbane> => |5905>
population |Brisbane> => |1857594>
annual-rainfall |Brisbane> => |mm: 1146.4>
area |Darwin> => |112>
population |Darwin> => |120900>
annual-rainfall |Darwin> => |mm: 1714.7>
area |Hobart> => |1357>
population |Hobart> => |205556>
annual-rainfall |Hobart> => |mm: 619.5>
area |Melbourne> => |1566>
population |Melbourne> => |3806092>
annual-rainfall |Melbourne> => |mm: 646.9>
area |Perth> => |5386>
population |Perth> => |1554769>
annual-rainfall |Perth> => |mm: 869.4>
area |Sydney> => |2058>
population |Sydney> => |4336374>
annual-rainfall |Sydney> => |mm: 1214.8>
----------------------------------------
Now, let's pretty print it:
sa: table[city-name,area,population,annual-rainfall] "" |city list>
+-----------+------+------------+-----------------+
| city-name | area | population | annual-rainfall |
+-----------+------+------------+-----------------+
| Adelaide | 1295 | 1158259 | mm: 600.5 |
| Brisbane | 5905 | 1857594 | mm: 1146.4 |
| Darwin | 112 | 120900 | mm: 1714.7 |
| Hobart | 1357 | 205556 | mm: 619.5 |
| Melbourne | 1566 | 3806092 | mm: 646.9 |
| Perth | 5386 | 1554769 | mm: 869.4 |
| Sydney | 2058 | 4336374 | mm: 1214.8 |
+-----------+------+------------+-----------------+
Cool and pretty! Heaps more to come!
Home
previous: new function pretty print a table
next: another pretty print table example
updated: 19/12/2016
by Garry Morrison
email: garry -at- semantic-db.org