![]() |
| ||||||
Navigation |
Synopsis Retrieve a value by its key in map.
Syntax
Exp1 [ Exp2 ]
Types
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") rascal>colors["trumps"]; str: "black"Explore some erroneous subscription expressions: rascal>colors[0]; |stdin:///|(7,1,<1,7>,<1,8>): Expected str, but got int rascal>colors["square"]; |stdin:///|(7,8,<1,7>,<1,15>): NoSuchKey("square") at ___SCREEN_INSTANCE___(|stdin:///|(0,17,<1,0>,<1,17>)) ![]() |