dcolthorp / matchure

Powerful, idiomatic pattern matching for clojure
159 stars 8 forks source link

Blowing heap on if-match on or expression #6

Open tgk opened 13 years ago

tgk commented 13 years ago

When trying to construct a function for balancing a red-black tree we ran into a problem when constructing a set of four different patterns for matching a tree. The heap is blown when trying to compile the function below.

(defn balance [tree]
  (if-match [(or [:black [:red [:red ?a ?x ?b] ?y ?c] ?z ?d]
         [:black [:red ?a ?x [:red ?b ?y ?c]] ?z ?d]
         [:black ?a ?x [:red [:red ?b ?y ?c] ?z ?d]] 
         [:black ?a ?x [:red ?b ?y [:red ?c ?z ?d]]]) tree]
        [:red [:black a x b] y [:black c z d]]
        tree))

For a complete example, please see this gist

dcolthorp commented 13 years ago

Ouch. Thanks for the bug report. I'll look into this as soon as I can.