A Common Lisp implementation of R's tibble data frames.
cl-tibble provides a "surly" and "lazy" data structure for tabular data. It enforces strict invariants (unlike standard alists/plists) while providing a modern, ergonomic API for data manipulation.
- Surly: Complains if columns are different lengths. Rejects invalid column names.
- Lazy: Does not coerce types. Does not partial match names.
- Rich Display: Pretty-printing with type abbreviations (
<int>,<dbl>) and automatic truncation. - Ergonomic: "Lispy" DSL (
with-tibble,chain) for easy data manipulation.
Clone into your local-projects directory:
cd ~/common-lisp/ # or wherever your local-projects are
git clone https://github.com/yourusername/cl-tibble.gitLoad with Quicklisp:
(ql:quickload :cl-tibble)tibble: The standard constructor. Supports recycling of scalars.
(cl-tibble:tibble
:x #(1 2 3)
:y "val" ;; Recycled to #("val" "val" "val")
:z #(10 20 30))
;; #<A TIBBLE: 3 x 3>
;; x y z
;; <int> <chr> <int>
;; 1 "val" 10
;; 2 "val" 20
;; 3 "val" 30 tribble: Row-wise construction for inline data.
(cl-tibble:tribble
:name :age
"Alice" 25
"Bob" 30)as-tibble: Coerce alists or plists.
(cl-tibble:as-tibble '((:x . #(1)) (:y . #(2))))Tibbles print lazily, showing only the first 10 rows. For a structure overview, use glimpse:
(cl-tibble:glimpse df)
;; Rows: 3
;; Columns: 3
;; $ x <int> 1, 2, 3...
;; $ y <chr> "val", "val", "val"...tbl-col: Retrieve a column vector by name (string/keyword) or index.
(cl-tibble:tbl-col df :x) ;; => #(1 2 3)tbl-ref: Access a specific cell (row, col).
(cl-tibble:tbl-ref df 0 :y) ;; => "val"slice: Subset rows and columns (functional, returns new tibble).
(cl-tibble:slice df :rows '(0 2) :cols '(:x :z))Combine tibbles vertically or horizontally.
(cl-tibble:bind-rows df1 df2) ;; Fills missing columns with NIL
(cl-tibble:bind-cols df1 df2) ;; Requires matching row countswith-tibble: Lexically bind columns to variables.
(cl-tibble:with-tibble (df x y)
(print (aref x 0)))chain: Thread-first macro for pipelines.
(cl-tibble:chain (cl-tibble:tibble :x #(1 2))
(cl-tibble:bind-cols (cl-tibble:tibble :y #(3 4)))
(cl-tibble:slice :rows '(0)))do-rows: Iterate over rows.
(cl-tibble:do-rows (r df)
(print (getf r :x)))Run the test suite with:
make testOr in Lisp:
(asdf:test-system :cl-tibble)