Ordered Collections

Learn about the available ordered collections.

Lists

Lists are most commonly used in Clojure to represent code. However, they are singly linked lists with efficient access and modifications of the list head, but slow random access. They have their own type, clojure.lang.IPersistentList. They’re often used interchangeably with sequences, but we can find out if a collection is a list by calling the core function, list?.

How to instantiate a list

Clojure has no literal representation for lists because they’re interpreted as code. So we need to quote it to make it a list. But the problem with quoting is that it won’t evaluate the elements of the list, so this representation is only useful in lists of literals.

Press + to interact
; Quoting literals
(println
'(1 2 3))
; Quoting elements that would need to be evaluated as (+ 1 1)
(println
'(1 (+ 1 1) 3))

The solution to this situation of quotes is to use the list ...

Access this course and 1400+ top-rated courses and projects.