RSS Feed

Lisp Project of the Day

cl-ascii-table

You can support this project by donating at:

Donate using PatreonDonate using Liberapay

cl-ascii-tableconsoleuitext

Documentation😀
Docstrings🥺
Tests 🥺
Examples😀
RepositoryActivity🥺
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 "bob@gmail.com" 89.4)
                               ("Alice" 28 "alice@hot.com" 65.1)
                               ("Garry" 25 "garry@zoumz.in" 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 | bob@gmail.com  |   89.4 |
| Alice |  28 | alice@hot.com  |   65.1 |
| Garry |  25 | garry@zoumz.in |   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