Table of Contents

Table operations — filter or combine tables

This section within the library of babel provides table operations.
See the documentation just below for details and working examples.

Author : Marc-Oliver Ihm <ihm@ferntreffer.de>
Version : 1.0

Documentation

Introduction

The table operations (currently four) are grouped in two categories:

Filtering the rows of a single table: keeping or removing

Combining two tables into one: merging or intersecting

All four operations are demonstrated below.

Example tables

To demonstrate we need three tables: upper, lower and keys:

1

A

3

C

4

D

10

J

2

B

Position

Letter

2

b

4

d

5

e

6

h

Position

1

2

4

The tables upper and lower both have two columns and associate a position in
the alphabet with the matching letter. E.g. the row "| 1 | A |" from table
upper, just states that the letter "A" comes at position 1 in the alphabet.

Nearly the same is true for table lower, only that it contains lower case
letters. Some of its letters (e.g. "b") have counterparts in table upper
("B"), some (e.g. "e") dont.

The table keys finally, contains keys (i.e. positions within the alphabet),
that can be used to select rows from either table upper or lower.

Note, that tables may have column headings or not.

Filtering a table

Keeping rows

Let's say, we want to select the upper-case letters (i.e. rows from the
table upper), that are given in table keys (i.e. the first, second and
fourth letter).

This can be described as filtering table upper and keeping only those rows,
that appear in table keys.

As a babel-call, this reads:

1

A

4

D

2

B

,which gives exactly those rows from table upper, that are specified in
keys.

Removing rows

Now, if on the contrary you want to filter table upper to remove any rows,
which are given in table keys:

Position

t2c2

3

C

10

J

,which is the expected result.

Please note, that the call contains the header argument ":colnames yes",
which causes the result table to contain the headings "Position" and
"t2c2". These headings are taken from the input-tables upper and
keys. However, as upper does not contain any headings, the heading "t2c2"
is generated artificially; it stands for "table 2 column 2".

If you do not want to have column names in the result table, just leave out
the header argument ":colnames yes" like in the first example. Note
however, that ":colnames no" does not give the expected effect.

Combining tables

Now, lets have a look at the tables upper and lower alone and see how to
combine them.

Note, that we only look at combining two tables for simplicity, however, all
operations can be easily scaled up to seven tables.

Merging rows

We have two tables, one with upper case letters and one with lower
case. What now, if you want to have only one table, which contains both,
upper and lower case letters ?

You may want to merge them:

Position

t1c2

Letter

1

A

2

B

b

3

C

4

D

d

5

e

6

h

10

J

This result combines both upper and lower case letters and lists them by
their position within the alphabet.

Intersecting rows

If you only want the rows, that are complete (i.e. have both upper and
lower case letters) you may compute the intersection:

2

B

b

4

D

d

,which has only those keys and letters, that appear in both tables.

Note, that we have ommitted the headeragument ":colnames yes" so that the
result table has no headings.

Internals

This section is not required if you just want to use table operations as
described above. Only if you are curious about its implementation or
development, you might want to have a look.

Implementation

Here is the actual lisp code, that implements the functionality of table
operations.