hey y'all I'm trying to write a pattern to match lists with two or more items, and I'm seeing the "n or more" operator match on a empty list when I use it in an m/search - here's what I'm seeing:
(m/match
[]
[_ ..2] :matched-two-or-more
_ :didnt-mach)
;; => :didnt-mach
(m/search
[]
[_ ..2] :matched-two-or-more)
;; => (:matched-two-or-more)
Is this expected behavior? I would assume that [_ ..2] means 2 or more elements in the list(m/match [1 2]
(m/pred #(< 1 (count %))) :more
_ :one)
This looks like a bug. Could you file it in the issue tracker? As a temporary work around try
[_ _ & _]
sure thing -- will do! FWIW, the pattern I ended up using was [_ . _ . _ ...] but [_ _ & _] worked as expected as well
alright, https://github.com/noprompt/meander/issues/228#issue-1133344037 - lmk if there's anything else I can help with
(m/defsyntax
compare-op
[op a b]
(case op
:eq `(= ~a ~b)
:not-eq `(not= ~a ~b)
:lt `(< ~a ~b)
:lt-e `(<= ~a ~b)
:gt `(> ~a ~b)
:gt-e `(>= ~a ~b)
:is `(= ~a ~b)
:is-not `(not= ~a ~b)
:in `(some #{~a} ~b)
:not-in `(not (some #{~a} ~b))))
(m/rewrite {:node :eq
:a 1
:b 2}
{:node :eq
:a ?a
:b ?b}
(compare-op :eq ?a ?b))
;; (clojure.core/= 1 2)
(m/rewrite {:node :eq
:a 1
:b 2}
{:node ?op
:a ?a
:b ?b}
(compare-op ?op ?a ?b))
;; 1. Caused by java.lang.IllegalArgumentException
;; No matching clause: ?op
How can I understand what’s going on here?When compare-op is expanded it is handed the literal arguments ?op, ?a, and ?b. The case is failing because ?op (the literal symbol ?op) has no clause.
defsyntax for all intents and purposes is like defmacro.
defsyntax defined functions are being called with literal arguments.
Oh, I get it. ?op doesn’t show up anywhere on the rhs of that rewrite rule.
Thanks!