sirherrbatka / vellum

Data Frames for Common Lisp
BSD 2-Clause "Simplified" License
76 stars 10 forks source link

more table creation examples needed #13

Closed slyrus closed 3 years ago

slyrus commented 3 years ago

Yes it would be nice to have better built-in parsing tools (CSV, xlsx, etc...) but I'm struggling with just the basics of how one creates tables. If I know the names of the columns, that's easy enough to do with transform. But if I want to say, take a list of column names '(foo bar baz) and a list (or array) of values '((:moose 1 2) (:gazelle 3 4)), how do I load this into a table without having to know the column names ahead of time?

sirherrbatka commented 3 years ago

Well, you can refer to the column via RR function. For instance you can just call transform with the following bind-row.

(vellum:bind-row () (iterate (for column in '(foo bar baz)) (for value in '(:moose 1 2)) (setf (vellum:rr column) value))

I will add more examples in the future.

sirherrbatka commented 3 years ago

Actually, right now we can even...

(defparameter *table*
   (vellum:to-table '((:moose 1 2) (:gazelle 3 4))
     :columns '(animal category1 category2)))

This will work on all nested sequences and more...

sirherrbatka commented 3 years ago

The interface is built around the cl-ds ranges, so as a result you can use cl-ds:xpr (lazy sequence generator).

(defparameter *table*
  (vellum:to-table (cl-ds:xpr (:i 0)
                     (when (< i 500)
                       (cl-ds:send-recur (list i)
                                         :i (1+ i))))
                   :columns '(iota)))
sirherrbatka commented 3 years ago

To clarify: I will add this to the readme, I am using this issue as notepad ;-)

sirherrbatka commented 3 years ago

@slyrus ok, i added few use cases for TO-TABLE. I will add more on it later, as it appears I really neglected it. There is actually even more to unpack here. I encourage you to take a look at the current readme, maybe the sliding window example will inspire you.

sirherrbatka commented 3 years ago

I think that this will suffice for now.