RSS Feed

Lisp Project of the Day


You can support this project by donating at:

Donate using PatreonDonate using Liberapay

Or see the list of project sponsors.


Tests 🥺
CI 🥺

Today I want to cheat and to review a library you've already seen in action in the data-table's review.

Recently I encounter a task where I needed to print tabulated data. In Python there is really cool library tabulate and first thing I did - created the post on Reddit asking if there is something similar for Common Lisp exists.

Comments didn't give a variety of choices, but I found a cl-ascii-table on Quickdocs. Remember, if you need to solve some problem - search o Quickdocs first! ;-)

So, cl-ascii-table is a little helper to draw nice ASCII tables. It is very easy to use. Just create a table, then add rows, and command it to render the table:

POFTHEDAY> (loop with rows = '(("Bob" 31 "" 89.4)
                               ("Alice" 28 "" 65.1)
                               ("Garry" 25 "" 76.3))
                 with table = (ascii-table:make-table
                               '("Name" "Age" "Email" "Weight")
                               ;; this is optional
                               :header "Sport Group")
                 for row in  rows
                 do (ascii-table:add-row table row)
                 finally (ascii-table:display table))
|              Sport Group              |
| Name  | Age | Email          | Weight |
| Bob   |  31 |  |   89.4 |
| Alice |  28 |  |   65.1 |
| Garry |  25 | |   76.3 |

It is not so featureful as Python's tabulate, but does it job.

By the way, pay attention on the difference between system name and package name. It might be important if you use package-inferred-system ASDF extension for your own system.

In this case, you can put this line into your ASD file. This will let ASDF to know which system should be loaded when you are importing symbols from ascii-table package:

(register-system-packages "cl-ascii-table" '(#:ascii-table))

Brought to you by 40Ants under Creative Commons License