whichever

whichever, table creation

There are other concepts named whichever.
See the entire list.

The contextual keyword whichever modifies the by table creation statement.

When the modifier whichever is present, table creation discards all lines for every group, except one arbitrarily chosen. The vectors of the originating table are copied into the newly created table.

Example:

table T = with
  [| as Code, as X |]
  [| "FR",    1    |]
  [| "US",    2    |]
  [| "UK",    3    |]
  [| "FR",    4    |]

table Countries[c] = whichever by T.Code

show table "Countries" a1b3 with c, Countries.X 

The resulting table may appear as shown below, where the value 4 corresponding to the "FR" group was arbitrarily dropped:

c X
FR 1
UK 3
US 2

In the above script, removing the whichever modifier prevents the script from compiling. Indeed, if there were several items in the "FR" group, Countries.X would be ambiguous, and thus Envision would not be able to determine which value to use.

In practice, the whichever by idiom is useful in situations where the choice of a duplicate has no effect, such as when all the lines are identical across all the vectors. Again, keep in mind that changing the script or upgrading to a newer version of Envision can result in different behaviour.

See also

User Contributed Notes
0 notes + add a note