Replies: 9 comments
-
I believe there is a restriction that the pattern to match with must be completely specified at compile time. You can enforce this by using an eval macro:
The "strategy" version of match returns a function, so
|
Beta Was this translation helpful? Give feedback.
-
@ribelo (let [m1 {:a 1}
m2 {:a 1 :b 2}
p (fn [] {:a 1})]
[(match m1 ~(p) :ok _ :fail)
(match m2 ~(p) :ok _ :fail)
(match m2 {:a 1} :ok _ :fail)])
;; =>
[:ok :fail :ok] I am open to compiling a more intelligent check pending some thought on the implications. |
Beta Was this translation helpful? Give feedback.
-
@noprompt What does "more intelligent check" mean? It appears to me that equality is the only sensible option, and is a feature... being able to match a literal map instead of a map pattern. So FWIW I don't think this behavior should be changed. Assuming you do want to preserve this behavior there are several places in the docs where it would be useful to call out how Stated another way; what is required here to close this issue? |
Beta Was this translation helpful? Give feedback.
-
I was thinking we could switch to interpretation where an internal matching function which does not bind for this purpose could be used. ~{:a 1, :b 2}
;; Compiles to
(m.match.runtime/matches? target-value {:a 1, :b 2}) But its unclear to me whether or not that is a good semantic or not. |
Beta Was this translation helpful? Give feedback.
-
Another question that comes to mind... is there a way to insert pattern literals into a pattern? I can't think of one besides the macro approach described above. (m/with-context [p {:a 2}]
...) FWIW I'm wary of the runtime binding approach. |
Beta Was this translation helpful? Give feedback.
-
Bah |
Beta Was this translation helpful? Give feedback.
-
@timothypratley I was just throwing out an idea. There's no such function at the moment. |
Beta Was this translation helpful? Give feedback.
-
oh right! :) |
Beta Was this translation helpful? Give feedback.
-
I'm open to supporting configuration of There are a number of possibilities but I think something like ^{::m/equality (var my-custom-equality)}
(m/<macro> ,,,) or ^{::m/equality my-custom-equality}
(m/<macro> ,,,) |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions