ListRelation

rascal-0.34.0

Synopsis​

List relations are lists of tuples with relational calculus operators defined on them.

Syntax​

`[ < Exp₁₁, Exp₁₂, ... > , < Exp₂₁, Exp₂₂, ... > , ... ]`

Types​

`Exp₁₁``Exp₁₂`...`{ < Exp₁₁, Exp₁₂, ... > , ... }`
`T₁``T₂`...`lrel[T₁, T₂, ... ]`

Description​

A list relation is a list of elements with the following property:

• All elements have the same static tuple type.

ListRelations are thus nothing more than lists of tuples, but since they are used so often we provide a shorthand notation for them. ListRelations are represented by the type `lrel[T₁ L₁, T₂ L₂, ... ]`, where T₁, T₂, ... are arbitrary types and L₁, L₂, ... are optional labels. It is a shorthand for `list[tuple[T₁ L₁, T₂ L₂, ... ]]`.

An n-ary list relation with m tuples is denoted by `[< E₁₁, E₁₂, ..., E₁ₙ>,< E₂₁, E₂₂, ..., E₂ₙ>, ..., < Eₘ₁, Eₘ₂, ..., Eₘₙ>]`, where the Eᵢⱼ are expressions that yield the desired element type Tᵢ.

Since list relations are a form of list all operations (see List) and functions (see List) are also applicable to relations.

The following additional operators are provided for list relations:

There are also library functions available for list relations.

Examples​

``rascal>[<1,10>, <2,20>, <3,30>]lrel[int,int]: [  <1,10>,  <2,20>,  <3,30>]``

Instead of `lrel[int,int]` we can also give `list[tuple[int,int]]` as type of the above expression remember that these types are interchangeable.

``rascal>[<"a",10>, <"b",20>, <"c",30>]lrel[str,int]: [  <"a",10>,  <"b",20>,  <"c",30>]rascal>[<"a", 1, "b">, <"c", 2, "d">]lrel[str,int,str]: [  <"a",1,"b">,  <"c",2,"d">]``