Navigation
Synopsis Projection of tuple.
Syntax Exp < Field1, Field2 ... >
Description Exp should evaluate to a tuple or relation, and Fieldi should be a field name or an integer constant that refers to elements in the order in which they occur in the original value (counting from 0).
Examples Suppose we have a relation with traffic information that records the name of the day, the day number, and the length of the traffic jams at that day.
rascal>rel[str day, int daynum, int length] Traffic = 
>>>>>>>{<"mon", 1, 100>, <"tue", 2, 150>, <"wed", 3, 125>, 
>>>>>>> <"thur", 4, 110>, <"fri", 5, 90>};
rel[str day,int daynum,int length]: {
  <"wed",3,125>,
  <"mon",1,100>,
  <"thur",4,110>,
  <"tue",2,150>,
  <"fri",5,90>
}
rascal>Traffic<length,daynum>;
rel[int length,int daynum]: {
  <110,4>,
  <100,1>,
  <150,2>,
  <125,3>,
  <90,5>
}
rascal>Traffic<2,day>;
rel[int length,str day]: {
  <90,"fri">,
  <150,"tue">,
  <125,"wed">,
  <110,"thur">,
  <100,"mon">
}
Field projection thus selects parts from a larger value that has a fixed number of parts. The selection is based on position and not on value and can be used to completely reorder or remove the parts of a larger value.
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 ask.rascal-mpl.org.