Welcome! Please see the About page for a little more info on how this works.

0 votes
in core.match by

Currently it is not possible to use list literals with or without variables in a pattern.
Thus something like this

`
(match ['(1 2 3)]

   ['(a b c)] a)

`

will result in a failing assert.

AssertionError Invalid list syntax (a b c) in (quote (a b c)).

There is a workaround for this by using :seq and :guard, as in

`
(match ['(1 2 3)]

   [(([a b c] :seq) :guard list?)] a)

`

but it is rather tedious to write.

List matching would be very useful when writing macros and compilers.

2 Answers

0 votes
by

Comment made by: glchapman

Note that you can use the core.match emit-pattern-for-syntax multimethod to add match syntax sugar:

(defmethod m/emit-pattern-for-syntax [:list :default] [[_ & pats]] (m/emit-pattern `(([~@pats] :seq) :guard list?)))

With the above:

user=> (m/match ['(1 2 3)] [(:list a b c)] a) 1

0 votes
by
Reference: https://clojure.atlassian.net/browse/MATCH-103 (reported by alex+import)
...