The rewriting paradigm of Stratego is functional in nature, which is somewhat contradictory to the imperative nature of hashtables. Normally, this doesn't present any practical problems, but remember that changes to hashtables "stick", i.e. they are changed by side-effect.
The Stratego hashtable API is pretty straightforward. Hashtables
are created by
new-hastable and destroyed by
stratego>new-hashtable => h Hashtable(136604296)
Hashtable(136604296) here is a handle
to the actual hashtable. Consider it a pointer, if you will. The
content of the hashtable must be retrieved with the
hashtable-* strategies, which we introduce here. The
hashtable-copy can be used to copy a hashtable.
Adding a key with value to the table is done with
k is the key,
v is the value. Retrieving the value again can be
stratego><hashtable-put(|"one", 1)> h Hashtable(136604296)
The contents of the hashtable can be inspected with
Nesting is also supported by the Stratego hashtables. Using
hashtable-push(|k,v), a new "layer" can be added
to an existing key (or an initial layer can be added to
a non-existing key). Removing a layer for a key can be done
stratego><hashtable-push("one",2)> h Hashtable(136604296)
stratego><hashtable-get("one")> h [2,1]
stratego><hashtable-pop(|"one")> h Hashtable(136604296)
stratego><hashtable-get(|"one")> h 
stratego><hashtable-remove(|"one")> h Hashtable(136604296)
stratego><hashtable-values> h 
The library provides a rather feature complete implementation of indexed sets, based on hashtables. A lightweight implementation of sets, based on lists, is explained in Chapter 22.
Similar to hashtables, indexed sets are created with the
new-iset strategy, copied with
iset-copy and destroyed with
stratego>new-iset => i IndexedSet(136662256)
The resulting term,
IndexedSet(136662256), is a handle
to the actual indexed set, which can only be manipulated through
Adding a single element to a set is done with
iset-add(|e), whereas an entire list can be added
iset-addlist(|es). Its elements can be
returned as a list using
stratego><iset-addlist(|[1,2,3,4,4])> i IndexedSet(136662256)
Notice that the result is indeed a set: every value is only represented once.
iset-get-index(|e), the index of a given
e can be found. Similarly,
iset-get-elem(|i) is used to get the value for
a particular index.
stratego><iset-get-index(|3)> i 2
stratego><iset-get-elem(|3)> i 4
Note that the indexes start at 0.
The set intersection between two sets can be computed with
iset-isect(|set2) strategy. The
iset-union(|set2) calculates the union
of two sets, whereas
checks if one set is a subset of another. Equality between
two sets is checked by
strategies are all used in a similar way:
A single element can be removed from the set with
remove all elements in a set, thus emptying it.