Selecting Array literals
(arr)
selects array literals and, optionally, their elements. It has the following signature:
clojure
(arr [elems?])
In its bare form, (arr)
will match any array literals, like []
, [a]
, or [...x]
:
clojure
(arr)
To specify constraints for the elements of an array literal, the (el)
selector can be used, which has the following signature:
clojure
(el [pos?] [val])
Using what we learned in the previous chapter on literals, the following query selects array literals that have a number for their first element, like [42]
:
clojure
(arr (el 1 (num)))
Conversely, when we don't care about the position of the element, only its type or value, we may use the placeholder atom to disregard its position:
clojure
(arr (el _ (num)))
Which will match [77, 'a']
and ['a', 77]
but not ['a']
.