![]() |
| ||||||||
Navigation |
Synopsis Relation values.
Syntax
{ <Exp11, Exp12, ... > , <Exp21, Exp22, ... > , ... }
Types
Details CartesianProduct Composition FieldSelection Join ReflexiveTransitiveClosure Subscription TransitiveClosure
Description A relation is a set of elements with the following property:
rel[T1 L1, T2 L2, ... ] , where T1 , T2 , ... are arbitrary types and
L1 , L2 , ... are optional labels. It is a shorthand for set[tuple[T1 L1, T2 L2, ... ]] .
An n-ary relations 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 relations are a form of set all operations (see Set) and functions (see Prelude/Set) are also applicable to relations. The following additional operators are provided for relations:
Examples
rascal>{<1,10>, <2,20>, <3,30>}
rel[int,int]: {
<3,30>,
<2,20>,
<1,10>
}
instead of rel[int,int] we can also give set[tuple[int,int]] as type of the above expression
remember that these types are interchangeable.
rascal>{<"a",10>, <"b",20>, <"c",30>} rel[str,int]: { <"c",30>, <"b",20>, <"a",10> } rascal>{<"a", 1, "b">, <"c", 2, "d">} rel[str,int,str]: { <"a",1,"b">, <"c",2,"d"> } Questions
Question [1].
![]() ![]() ![]() |