Skip to main content

Map Union

rascal-0.34.0

Synopsis

Union of two maps.

Syntax

Exp₁ + Exp₂

Types

Exp₁Exp₂Exp₁ + Exp₂
map[TK₁, TV₁]map[TK₂, TV₂]map[lub(TK₁,TK₂),lub(TK₁,TK₂) ]

Description

The result is the union of the two map values of Exp₁ and Exp₂. If they have a pair with the same key in common, that key will be associated in the union with the value associated with that key in Exp₂.

Examples

rascal>("apple": 1, "pear": 2) + ("banana": 3, "kiwi": 4);
map[str, int]: ("banana":3,"pear":2,"kiwi":4,"apple":1)
rascal>("apple": 1, "pear": 2) + ("banana": 3, "apple": 4);
map[str, int]: ("banana":3,"pear":2,"apple":4)

Benefits

Map union is very suited for representing environment composition in interpreters.