![]() |
| ||||||||||||||||
Navigation |
Synopsis Indexing of a relation via tuple values.
Syntax
Types
Variant 1
Variant 2
Description Relation resulting from subscription of a relation
Exp0 .
Variant 1Subscription with the index values ofExp1 , Exp2 , ....
The result is a relation with all tuples that have these index values as first elements
with the index values removed from the tuple.
If the resulting tuple has only a single element, a set is returned instead of a relation.
A wildcard _ as index value matches all possible values at that index position.
Variant 2Subscription with a set of the index values ofExp1 .
The result is a relation with all tuples that have these index values as first element
with the index values removed from the tuple.
Examples
rascal>R = {<1,10>, <2,20>, <1,11>, <3,30>, <2,21>}; rel[int,int]: { <1,11>, <3,30>, <2,21>, <2,20>, <1,10> } rascal>R[1]; set[int]: {10,11} rascal>R[{1}]; set[int]: {10,11} rascal>R[{1, 2}]; set[int]: {10,11,20,21} rascal>RR = {<1,10,100>,<1,11,101>,<2,20,200>,<2,22,202>, >>>>>>> <3,30,300>}; rel[int,int,int]: { <3,30,300>, <2,22,202>, <1,11,101>, <1,10,100>, <2,20,200> } rascal>RR[1]; rel[int,int]: { <11,101>, <10,100> } rascal>RR[1,_]; set[int]: {100,101}Introduce a relation with economic data and assign it to GDP :
rascal>rel[str country, int year, int amount] GDP = >>>>>>>{<"US", 2008, 14264600>, <"EU", 2008, 18394115>, >>>>>>> <"Japan", 2008, 4923761>, <"US", 2007, 13811200>, >>>>>>> <"EU", 2007, 13811200>, <"Japan", 2007, 4376705>}; rel[str country,int year,int amount]: { <"US",2007,13811200>, <"US",2008,14264600>, <"Japan",2007,4376705>, <"Japan",2008,4923761>, <"EU",2008,18394115>, <"EU",2007,13811200> }and then retrieve the information for the index "Japan" :
rascal>GDP["Japan"];
rel[int,int]: {
<2008,4923761>,
<2007,4376705>
}
or rather for the indices "Japan" and 2008 :
rascal>GDP["Japan", 2008];
set[int]: {4923761}
Questions
Question [1].
![]() ![]()
Question [2].
![]() ![]() ![]() |