Synopsis Retrieve a value by its key in map.
Syntax Exp1 [ Exp2 ]
Exp1 Exp2 Exp1 [ Exp2 ]
map[T1, T2] T1 T2
Description Map subscription uses the value of Exp2 as key in the map value of Exp1 and returns the associated value. If this key does not occur in the map, the exception NoSuchKey is thrown.
Examples Introduce a map, assign it to colors, and retrieve the element with index "trumps":
rascal>colors = ("hearts":"red", "clover":"black", 
>>>>>>>          "trumps":"black", "clubs":"red");
map[str, str]: ("hearts":"red","trumps":"black","clover":"black","clubs":"red")
str: "black"
Explore some erroneous subscription expressions:
|stdin:///|(7,1,<1,7>,<1,8>): Expected str, but got int
|stdin:///|(7,8,<1,7>,<1,15>): NoSuchKey("square")
	at ___SCREEN_INSTANCE___(|stdin:///|(0,17,<1,0>,<1,17>))

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