Synopsis ListRelation values.
Syntax [ <Exp11, Exp12, ... > , <Exp21, Exp22, ... > , ... ]
Exp11 Exp12 ... { <Exp11, Exp12, ... > , ... }
T1 T2 ... lrel[T1, T2, ... ]
Usage import ListRelation; (included in Prelude)
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[T1 L1, T2 L2, ... ], where T1, T2, ... are arbitrary types and L1, L2, ... are optional labels. It is a shorthand for list[tuple[T1 L1, T2 L2, ... ]].

An n-ary list relation with m tuples is denoted by [<E11, E12, ..., E1n>,<E21, E22, ..., E2n>, ..., <Em1, Em2, ..., Emn>], where the Eij are expressions that yield the desired element type Ti.

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

The following additional operators are provided for list relations: The following additional functions are provided on list relations:
  • carrier: Return the set of all elements in any tuple in a list relation.
  • carrierR: A list relation restricted to certain element values in tuples.
  • carrierX: A list relation excluding tuples that contain certain element values.
  • complement: Complement of a list relation.
  • domain: Domain of a list relation: a list consisting of the first element of each tuple.
  • domainR: List relation restricted to certain domain elements.
  • domainX: List relation excluding certain domain values.
  • groupDomainByRange: Make sets of elements in the domain that relate to the same element in the range.
  • groupRangeByDomain: Make sets of elements in the range that relate to the same element in the domain.
  • ident: The identity list relation.
  • index: Listes a binary list relation as a map
  • invert: Invert the tuples in a list relation.
  • range: The range (i.e., all but the first element of each tuple) of a list relation.
  • rangeR: List relation restricted to certain range values.
  • rangeX: List relation excluding certain range values.
rascal>[<1,10>, <2,20>, <3,30>]
lrel[int,int]: [
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]: [
rascal>[<"a", 1, "b">, <"c", 2, "d">]
lrel[str,int,str]: [

Question [1]. A relation:

Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit