Skip to content
Leon Starr edited this page Sep 5, 2021 · 1 revision

The rank operation adds a column with an ascending or descending order based on some value.

rankedAltitudes #= Aircraft[>>Lrank:^-Altitude]

The resulting table includes all of the Aircraft attributes with an added column named Lrank filled with an integer rank value for each Altitude value. The rank values start at 1 for the lowest altitude and increasing for higher altitudes.

The : and ^- symbols have a different meaning in the context of a projection expression than they do in the restriction expression. Specifically, : serves as a delimiter and ^- and ^+ mean descending and ascending, respectively.

The operation can be useful when you want to find the n highest or lowest aircraft. For example:

ranked by altitude #= Aircraft[>>Hrank:^+Altitude]
n highest rows #= ranked by altitude(Hrank < n)
n highest aircraft #= n highest rows.(-Hrank)

First we add the Hrank column with altitudes ranked with 1 representing the highest altitude. Then we grab all Aircraft with a ranking less than n. Finally, we drop the Hrank column.

We can dispense with the intermediate variables and use a single expression to produce the same result:

N highest aircraft #= Aircraft[>>Hrank:^+Altitude](Hrank < n).(-Hrank)

In fact, we could go further and convert the table back into an instance set value like so:

High fliers::Aircraft ..= N highest aircraft.Tail number

This eliminates the need for dropping the Hrank column, so the expression yielding an instance set becomes:

High fliers::Aircraft ..= Aircraft[>>Hrank:^+Altitude](Hrank < n).Tail number

Introduction

Model semantics

Flows (as Variables)

Constants and literals

Structure of an activity

Accessing the class model

Data flow


Grammar and parsing notes

Components

Clone this wiki locally