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

0 votes
ago in Libs by

Here’s a repro:

  (defn wut [foo m]
    (match m
      [:m foo] :foo))

  (wut 1 [:m 2])
  ;; Execution error (IllegalArgumentException) at user/wut (REPL:560).
  ;; No matching clause: [:m 2]

The gotcha here is that I am using foo both as an argument and as a local match binding. This works:

  (defn wut [foo m]
    (match m
      [:m bar] :foo))
  
  (wut 1 [:m 2])
  ;;=> :foo

I'm not sure if this is just what it is or if it is a problem that can be handled better by core.match? It def surprised me a lot and took a lot of time to figure out.

1 Answer

+1 vote
ago by
selected ago by
 
Best answer

It's a deliberate documented behavior, https://github.com/clojure/core.match/wiki/Basic-usage#locals:

Normally core.match will bind values to symbols, however it first tries to match against locals.

Changing it would definitely be a breaking change.

...