Magic Pipes
Documentation
Login

mpalist2table [-H] [key|(key default)]...

Accepts alists on standard input, and converts them to a table (sequence of list s-exprs with the same length) by extracting a list of keys specified on the command line.

If a default is given for a key, then that default value is output in the given column of the table when the key is missing from an input alist. Otherwise, an error is signalled if the key is missing.

If the -H flag is provided, then the list of keys is output as an initial header row before the alist conversion begins.

This useful for interoperating between mpcsv and mpsqlite.

Examples

$ echo '((a . 1) (b . 2))' | mpalist2table a b
(1 2)
$ echo '((a . 1) (b . 2))' | mpalist2table -H a b
(a b)
(1 2)
$ echo '((a . 1) (b . 2)) ((a . 123))' | mpalist2table a '(b #f)'
(1 2)
(123 #f)