Association lists
Factor handbook » The language » Collections

Prev:Hashtables
Next:Enumerations


An association list, abbreviated alist, is an association represented as a sequence where all elements are key/value pairs. The sequence mixin is an instance of the assoc mixin, hence all sequences support the Associative mapping protocol in this way.

While not an association list, note that f also implements the associative mapping protocol in a trivial way; it is an immutable assoc with no entries.

An alist is slower to search than a hashtable for a large set of associations. The main advantage of an association list is that the elements are ordered; also sometimes it is more convenient to construct an association list with sequence words than to construct a hashtable with association words. Much of the time, hashtables are more appropriate. See Hashtables.

There is no special syntax for literal alists since they are just sequences; in practice, literals look like so:
{ { key1 value1 } { key2 value2 } }

To make an assoc into an alist:
>alist ( assoc -- newassoc )