 To understand the remaining essential collection functions you must first understand sequences. What Clojure calls a sequence is not any particular collection type, but rather an interface, a set of operations implemented by some collections. The first function returns the first element of the collection, calling first on a sequence of zero elements returns nil. The rest function returns a copy of the sequence with the first element removed. Calling rest on a sequence with no elements or just one element returns an empty sequence. Strictly speaking, only types which implement the Java interface Clojure.lang.iceq are sequences. However, many collection types which do not implement this interface are considered sequenceable or as we say, seekable, because they have one or more operations which produce sequences. For many seekable types, we can use the seek function, Seq, to get a sequence of their elements. For example, the map and vector types do not themselves implement ISeq, but calling seek on a map or vector returns a sequence of its elements. This extra step may seem silly, especially for vectors. If we can produce a sequence from a vector, why shouldn't the vector just be its own sequence? To my understanding, the rationale is that the rest operation is intended to return a sequence of its own type, but for efficiency reasons, rest called on a sequence produced from a vector does not return another vector. Instead, rest returns a sequence object that references the original vector, but with an offset such that the sequence starts at an index of a vector other than zero. These sequence objects are cheaper to produce than new vectors, and a core goal of the sequence operations is to allow for quick iteration through all the elements of the sequence. In contrast, list objects are themselves sequences because their implementation allows for very cheap first and rest operations. Rest on a list returns a new list, whose head is the second node of the original list. For a map, it's more natural that we don't consider them sequences. When you call the seek function on a map, it returns a sequence of its key value pairs as two element vectors. If we want a sequence of just the keys, we use the keys function, and if we want a sequence of just the values, we use the vowels function. Be clear that items in a hash map have no defined order, so you shouldn't expect the items in the return sequences to be in any particular order. So that's why some collections are themselves sequences, but others are merely seekable. In practice though, the distinction is usually really not that important, because most functions that operate on sequences, including the first and rest functions, actually call seek on their argument. So here, when we use first and rest on a map and vector, we can pass the map and vector directly rather than call seek on them ourselves. A core purpose of the sequence interface is to enable iteration over collections. Here for example, we use the special forms loop and recur with the first and rest functions to iterate through every element of a vector. Note that, unlike a conventional iterator, a sequence has no mutable state. Each called rest returns a new sequence, and every sequence instance is immutable. The name cons comes from old dialects of lisp, where it was short for construct, as in construct list. Over time, cons became a noun denoting a list-like data structure. In closure, a cons is an object that holds a value and references another sequence. The cons function creates a cons, though if the second argument is nil, cons returns a list instead. Here, this first called cons returns a list with one element three, but the second called cons returns a cons, which has the value four, and references a list seven, eight, nine. Calling first on a cons returns its held value, and calling rest on a cons returns its referenced sequence. Because a cons itself is a kind of sequence, conses can reference other conses and thus form a chain. Here we deft to z, a cons with the value five, which references another cons with the value six, which references a list with one element three. This is very similar to the chain of nodes that make up a persistent list, but the difference is that list nodes may only link to other list nodes, not sequences. In a chain of conses, the last cons might reference some other kind of sequence, such as a list. As we'll see in a moment, this makes conses useful in connection with what are called lazy sequences. Transcribed by ESO, Translated by —