body { margin:0px; background-color:#fff } img { margin:0px; border-style:none } button { margin:0px; border-style:none; padding:0px; background-color:transparent; vertical-align:top } p:first-child { margin-top:0px } table { empty-cells:hide } .f-sp { font-size:1px; visibility:hidden } .f-lp { margin-bottom:0px } .f-x1 { } .f-x2 { } .f-x3 { } a:visited { color:#8b0000; text-decoration:underline } .capsub { color:#808080; font-weight:bold; text-transform:uppercase; letter-spacing:2.4px } .style31 { color:#000 } .style21 { margin-left:0px; margin-right:0px; text-align:center; margin-top:0px; margin-bottom:0.1px } .style52 { color:#000; margin-left:0px; margin-right:0px; text-align:center; margin-top:0px; margin-bottom:0.1px } .code { color:#000; font-family:monospace } .style32 { color:#000 } .rightaligned { margin-left:0px; margin-right:0px; text-align:right; margin-top:0px; margin-bottom:0.1px } .style53 { color:#000; margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0.1px } .small { color:#000; font-size:90% } .style42 { color:#000; font-weight:bold; font-size:90% } .style33 { color:#808080; font-style:italic; font-size:90% } .style54 { color:#808080; font-style:italic; font-size:90%; margin-left:0px; margin-right:0px; text-align:center; margin-top:0px; margin-bottom:0.1px } .footer { color:#808080; font-size:90% } .FWExtra { } .FWExtra a:link { text-decoration: none; } .FWExtra a:active { text-decoration: none; } .FWExtra a:visited { text-decoration: none; } .FWExtra a:hover { text-decoration: underline; } -->
Equi4 Softwareitem2

Jump to part:
1 - 2 - 3 - 4 - 5
API

an introduction to ratcl - Part 2

With the basics out of the way, it's time to go into some more substantial data manipulations. First, some demo data:

 % [view A,B,C

These create the following views:

item18

The examples below all use "functional operations" returning a new view without altering the input views. All the above views retain their original content.

 % [T maprow {0Selection of a view can be done through a "row map", i.e. a list of row numbers to keep:

 

Similarly, a column map can be used to extract a number of columns:

 % [T mapcol {A

 % [T project {AProjection returns a view with only the columns specified, and no duplicate rows:

 

Here's the cross-product:

 % [R product S]

 

 

Two variants of relational join:

 % [T join1 U]    % [T join0 U]

Relational join is a workhorse for many purposes, the above "join1" drops unmatched rows, while "join0" returns rows which did not match in the join.

 % [T divide V]Division is also a (lesser used) core operator of relational algebra:

 

 

Set operations

Set operations are straightforward. They take two views and return a new one:

 % [R union S]    % [R except S]    % [R intersect S]

 % [[T mapcol {AThe input views must be sets, i.e. contain no duplicate rows. If this is not the case, the "unique" operator can be used to produce a proper set:

This example shows that mapcol + unique is equivalent to a projection.

All views used for set operations must (for now) also have the same columns in the same order. This can be enforced through "mapcol" or "project".

Applying set operations on anything else leads to (as yet) undefined results.

no iteration

As you can see, relational algebra offers a way to manipulate structured collections of data in quite a few ways, without dealing with details of any implied iterations. Ratcl helps you think in terms of high-level transformations.

The next page describes one more important operator of relational algebra.

Continued...