Some of core.logic constructs (matcha
, matche
, matchu
, defne
, fne
) use pattern matching expressions as body and can be used such as:
(run* [q]
(fresh [a o]
(== a [1 2 3 4 5])
(matche [a]
([ [1 2 . [3 4 5] ]]
(== q "first"))
([ [1 2 3 . [4 5] ]]
(== q "second"))
([ [1 . _] ]
(== q "third")))))
;=> ("first"
; "second"
; "third")
(example from Logic-Starter wiki)
But I can't find specification of syntax for pattern matching in core.logic documentation. What is this syntax? Maybe I can find it in some minikanren docs or books?
- What is difference between matched variables prefixed with
?
and without it? - Is there any other destructing constructs in addition to lists with
.
(similar to&
in clojure)? - Will
[_ _]
match only sequences with two elements? - Is it possible to destruct maps?
_
expands to(lvar)
(see here). I don't think there is anything special about the?o
vso
– spelufo