One more very quick post before we get to the meat of the core library.


  (defprotocol Associative
    (assoc [m k v])
    (get [m k])
    (keys [m])
    (vals [m]))

The hash-map, under various names, is probably one of the most used data structures currently in use. Being able to associate a pair of values is hugely useful. You could probably make the argument that there's something fundemental there. Toccata specifies the Associative protocol to capture this abstraction so it can be applied more widely.


Establish a mapping between a key value k and value v in the collection m. Returns a new collection while m remains unchanged. The new collection is of the same type as m.


Retrieve the value associated with k from m. Since such an association may not exist in m, Implementations of this protocol must return a value of type Maybe (nothing or a Maybe value containing a value).


Return a (possibly empty) list of the keys in m.


Return a (possible empty) list of the values in m.

Next time

These last 3 posts cover most of the core Toccata protocols and should be pretty familiar for most programmers. The remaining one is the Container protocol. It's not really anymore difficult, but it is more abstract. So next time, we're going to change direction and start looking at concrete examples of Toccata code as we explore one aspect of what really sets Toccata apart.