Navigation
Synopsis Map values.
Syntax ( KeyExp1 : ValExp1, KeyExp2 : ValExp2, ... )
Types
KeyExp1 ValExp1 KeyExp2 ValExp2 ... ( KeyExp1 : ValExp1, KeyExp2 : ValExp2, ... )
TK1 TV1 TK2 TV2 ... map[lub(TK1, TK2, ... ) , lub(TV1, TV2, ... )]
Usage import Map; (included in Prelude)
Description A map is a set of key : value pairs and has the following properties:
  • Key and value may have different static types.
  • A key can only occur once.
Maps resemble functions rather than relations in the sense that only a single value can be associated with each key.

The following functions are provided for maps:

  • Composition: Composition of two map values.
  • Comprehension: A map comprehension generates a map value.
  • Difference: The difference between two maps.
  • Equal: Equality operator on maps.
  • in: Membership test on the keys of a map.
  • Intersection: Intersection of two maps.
  • NotEqual: Not equal operator on map values.
  • notin: Negated membership test on the keys of a map.
  • StrictSubMap: Strict submap operator on map values.
  • StrictSuperMap: Strict supermap operator on map values.
  • SubMap: Submap operator on map values.
  • Subscription: Retrieve a value by its key in map.
  • SuperMap: Supermap operator on map values.
  • Union: Union of two maps.
Examples
rascal>("pear" : 1, "apple" : 3, "banana" : 0);
map[str, int]: ("banana":0,"pear":1,"apple":3)

Questions
Question [1]. A map maps keys to values. In a map:




Question [2]. Complete this function that returns the set of keys with the smallest associated value.
Fill in
import Map;
import Set;
inventory = ("orange" : 20, "apple" : 15, "banana" : 25, "lemon" : 15);
public set[str] lowest(map[str,int] inv){
    m = ; // Determine the minimal value in the map
    return { s  | s <- inv, inv[s] == m };
}
and make the following true:
lowest(inventory) == {"apple", "lemon"};



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.