Fork me on GitHub
#meander
<
2021-12-28
>
Richie19:12:11

Why doesn't the second example match? cheshire parse-string is giving me an java.lang.Integer and I'm trying to join on some data but it's not matching...

(m/match 1
  1 :match
  _ :no)
;; => :match

(m/match (Long. 1)
  (Long. 1) :match
  _ :no)
;; => :no

(type 1)
;; => java.lang.Long

(type (Long. 1))
;; => java.lang.Long

Richie19:12:35

[meander/epsilon "0.0.650"]

Jimmy Miller19:12:30

Meander is matching that at the symbol level. It is looking for '(Long. 1)

(m/match (Long. 1)
  1 :match
  _ :no)

;; => :match

(m/match '(Long. 1)
  (Long. 1) :match
  _ :no)

;; => :match

Jimmy Miller19:12:30

If you want to just match all numbers, you can do something like thos

(m/match (Long. 1)
  (m/pred number? ?x) :match
  _ :no)

Richie20:12:41

good

(let [n (Integer. 2)]
  (m/find [n [{:a (Integer. 1)}
              {:a (Integer. 2)}]]
    [?n (m/scan (m/and {:a ?n} ?t))] ?t))
bad
(let [n (Integer. 2)]
  (m/find [{:a (Integer. 1)}
           {:a (Integer. 2)}]
    (m/scan (m/and {:a n} ?t)) ?t))
Thanks! Yea, I was thinking that it would have the value there but what you said makes total sense. It's term rewriting!