In general, pattern matching is not the right tool for comparing one variable with another. Patterns are supposed to be either literals such as 1
or :a
, destructuring expressions or variables to be bound. So, for example, take this expression:
(let [a 1
b 2]
(match [2]
[a] "It matched A"
[b] "It matched B"))
You might expect it to yield "It matched B" since the variable b
is equal to 2, but in fact it will bind the value 2 to a new variable named a
and yield "It matched A".
I think you're looking for condp =
. It's basically what you wish case
would be.
(condp = msg-type
MsgType/TYPE_1 (do-type-1-thing)
MsgType/TYPE_2 (do-type-2-thing))