operator: table

    description:
        table[op1, op2, ... , opn] sp
        display a nicely formatted table
        where: 
            the first column are elements from the inputted superposition/sequence
            the rest of the columns are the result of applying the given operator to the element in the first column

        we also have some special operators:
            '*' means use all supported-ops of the inputted superposition/sequence
            'coeff' means return the coeff of the element in the first column
            'rank' as the first operator means produce a rank table
        
    examples:
        load fred-sam-friends.sw
        age |Fred> => |47>
        age |Sam> => |45>
        table[person, age, friends] split |Fred Sam>
            +--------+-----+----------------------------------------------------+
            | person | age | friends                                            |
            +--------+-----+----------------------------------------------------+
            | Fred   | 47  | Jack, Harry, Ed, Mary, Rob, Patrick, Emma, Charlie |
            | Sam    | 45  | Charlie, George, Emma, Jack, Rober, Frank, Julie   |
            +--------+-----+----------------------------------------------------+
        
        web-load http://semantic-db.org/sw-examples/bots.sw
        Bella |*> #=> apply(|_self>, |bot: Bella>)
        Emma |*> #=> apply(|_self>, |bot: Emma>)
        Madison |*> #=> apply(|_self>, |bot: Madison>)
        table[op, Bella, Emma, Madison] supported-ops (|bot: Bella> + |bot: Emma> + |bot: Madison>)
            +------------------------+--------------+----------------+---------------------+
            | op                     | Bella        | Emma           | Madison             |
            +------------------------+--------------+----------------+---------------------+
            | name                   | Bella        | Emma           | Madison             |
            | mother                 | Mia          | Madison        | Mia                 |
            | father                 | William      | Nathan         | Ian                 |
            | birth-sign             | Cancer       | Capricorn      | Cancer              |
            | number-siblings        | 1            | 4              | 6                   |
            | wine-preference        | Merlot       | Pinot Noir     | Pinot Noir          |
            | favourite-fruit        | pineapples   | oranges        | pineapples          |
            | favourite-music        | genre: punk  | genre: hip hop | genre: blues        |
            | favourite-play         | Endgame      | No Exit        | Death of a Salesman |
            | hair-colour            | gray         | red            | red                 |
            | eye-colour             | hazel        | gray           | amber               |
            | where-live             | Sydney       | New York       | Vancouver           |
            | favourite-holiday-spot | Paris        | Taj Mahal      | Uluru               |
            | make-of-car            | Porsche      | BMW            | Bugatti             |
            | religion               | Christianity | Taoism         | Islam               |
            | personality-type       | the guardian | the visionary  | the performer       |
            | current-emotion        | fear         | kindness       | indignation         |
            | bed-time               | 8pm          | 2am            | 10:30pm             |
            | age                    | 31           | 29             | 23                  |
            | hungry                 |              |                | starving            |
            | friends                |              |                | Emma, Bella         |
            +------------------------+--------------+----------------+---------------------+
      
        load pretty-print-table-of-australian-cities.sw
        table[rank, city, population, area, annual-rainfall] reverse sort-by[population] "" |city list>
            +------+-----------+------------+------+-----------------+
            | rank | city      | population | area | annual-rainfall |
            +------+-----------+------------+------+-----------------+
            | 1    | Sydney    | 4336374    | 2058 | 1214.8          |
            | 2    | Melbourne | 3806092    | 1566 | 646.9           |
            | 3    | Brisbane  | 1857594    | 5905 | 1146.4          |
            | 4    | Perth     | 1554769    | 5386 | 869.4           |
            | 5    | Adelaide  | 1158259    | 1295 | 600.5           |
            | 6    | Hobart    | 205556     | 1357 | 619.5           |
            | 7    | Darwin    | 120900     | 112  | 1714.7          |
            +------+-----------+------------+------+-----------------+

        load temperature-conversion.sw
        F |*> #=> to-F |_self>
        K |*> #=> to-K |_self>
        table[C, F, K] range(|C: 0>, |C: 100>, |5>)
            +-----+-------+--------+
            | C   | F     | K      |
            +-----+-------+--------+
            | 0   | 32.0  | 273.15 |
            | 5   | 41.0  | 278.15 |
            | 10  | 50.0  | 283.15 |
            | 15  | 59.0  | 288.15 |
            | 20  | 68.0  | 293.15 |
            | 25  | 77.0  | 298.15 |
            | 30  | 86.0  | 303.15 |
            | 35  | 95.0  | 308.15 |
            | 40  | 104.0 | 313.15 |
            | 45  | 113.0 | 318.15 |
            | 50  | 122.0 | 323.15 |
            | 55  | 131.0 | 328.15 |
            | 60  | 140.0 | 333.15 |
            | 65  | 149.0 | 338.15 |
            | 70  | 158.0 | 343.15 |
            | 75  | 167.0 | 348.15 |
            | 80  | 176.0 | 353.15 |
            | 85  | 185.0 | 358.15 |
            | 90  | 194.0 | 363.15 |
            | 95  | 203.0 | 368.15 |
            | 100 | 212.0 | 373.15 |
            +-----+-------+--------+
       
    see also:
        such-that, sort-by
      
    TODO:
        implement transpose table. eg, bots.sw would be simpler.
        implement a sequence version, probably called stable

Home