Skip to content

Creating a table from a class

Leon Starr edited this page Apr 24, 2023 · 4 revisions

Any selection on a class that projects over a subset of that class’s attributes will generate a table value that you may assign to a table variable using the #= assignment operator.

The selection format for table values is:

<class or table>( <selection> ).( <projection> )

Here are some examples:

t1 #= Aircraft.(Altitude, Speed)  // creates a table
t2 #= Aircraft(1, ^+Altitude).(Altitude, Speed) // One row max table with max Altitude
t3 #= Aircraft(Tail Number: in.ID ) // One row max table with all attributes of Aircraft
rowqty = ??t3  // Number of rows in t1

You need not perform an assignment to create a table. You might nest a table construction or return a table as an output parameter. If you select all attributes, you will need to clarify that you want to generate a table rather than an instance set. To do this, preface your expression with the # symbol. For example:

=>> Aircraft // returns all Aicraft instance references

=>> #Aircraft // returns a table of all Aicraft data

Here is the general table construction format:

<class name>(<instance selection>).(<attribute selection>)

Here are some example expressions that construct a table:

Aircraft(*).(Heading, Airspeed)  // Two column table
Aircraft.(Heading, Airspeed) // Same table (all implied)
Aircraft.(-Tail number) // Table has all attributes except the Tail number
Aircraft.(-Heading, -Airspeed) // Table has all attributes except Heading and Airspeed
#Aircraft(1) // One arbitrary row, all attributes implied
#Aircraft(1).(*) // Same table
#Aircraft(*).(*I1) // Instance reference table on ID1
#Aircraft(*).(*I2) // Instance reference table on ID2
#Aircraft(1).(-*I1) // All attrs except I1 of some instance
Aircraft(Tailnumber : in.ID).Airspeed // Airspeed table
Aircraft(Tailnumber : in.ID) // Yields zero or one instance reference
x .= Aircraft(Tailnumber : in.ID) // Assigns instance references
t #= Aircraft(Tailnumber : in.ID).Airspeed // Zero or one airspeed in a table
t2 #= Aircraft(Tailnumber: in.ID) // Zero or one row table

So we can see that the - symbol excludes an attribute from a projection. Also the symbol *In refers to all attributes of identifier n. And -*In gives you all attributes except those in identifier n. And the * symbols selects all attributes when it appears in a projection

You can also produce some weird tables that are set-theory correct and often useful for true/false decisions:

Aircraft(*).() // No attributes, zero or one row
// True if one row, false if zero rows

Aircraft().() // No attributes, zero rows
// False

Aircraft().(*) // All attributes, zero rows
// False

To get a sense of how these might be useful, consider some examples:

speeds above ceiling #= Aircraft(Airspeed > ceiling).()
// returns table with zero attributes and zero or one row
speeds above ceiling?
    Speeds above ceiling -> : No speeds above ceiling -> me

You can never have duplicate rows in a table. So if six different speeds are found by the selection criteria, but zero attributes are returned we get six duplicate rows which yields a single row. If none are selected, then you get zero rows. Thus only two possible cardinalities can result when zero attributes are specified in the attribute projection expression.

Unless the above is part of more intricate table actions, there is no need to resort to table operations. You could get the same result with the less obscure:

Aircraft(Airspeed > ceiling)?
    Speeds above ceiling -> : No speeds above ceiling -> me

(The abbreviation of omitting the target instance in the “then” part when it matches the target in the “else” part is described in the conditional execution section).

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