<< Back to previous view

[MATCH-103] Support for lists in patterns. Created: 18/Dec/14  Updated: 18/Dec/14

Status: Open
Project: core.match
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: Jan-Paul Bultmann Assignee: David Nolen
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Currently it is not possible to use list literals with or without variables in a pattern.
Thus something like this

(match ['(1 2 3)]
       ['(a b c)] a)

will result in a failing assert.

AssertionError Invalid list syntax (a b c) in (quote (a b c)).

There is a workaround for this by using `:seq` and `:guard`, as in

(match ['(1 2 3)]
       [(([a b c] :seq) :guard list?)] a)

but it is rather tedious to write.

List matching would be very useful when writing macros and compilers.






[MATCH-102] Do :guard predicates really need to handle :clojure.core.match/not-found? Created: 17/Dec/14  Updated: 17/Dec/14

Status: Open
Project: core.match
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Tassilo Horn Assignee: David Nolen
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Clojure 1.7.0 beta4, core.match 0.3.0-alpha3



 Description   

I'm very new to core.match and just started playing around. Doing so, I came up with this example:

(for [x [[1 2 3]
	 [1 2 3 4]
	 {:a 17, :b 2}
	 {:a 23, :b 7}]]
  (match [x]
   [[a b c]]                    [a b c]
   [{:a a, :b 2}]               {:a a}
   [{:a (a :guard odd?), :b b}] {:a a, :b b}
   :else                        :no-match))

This errors with the message "IllegalArgumentException Argument must be an integer: :clojure.core.match/not-found clojure.core/even? core.clj:1351)". The problem is that the keyword :clojure.core.match/not-found is passed to the :guard function odd? which passes it to even?.

I can fix it by ensuring the my guard only gets an integer like so:

(for [x [[1 2]
        [1 2 3]
        [1 2 3 4]
        {:a 17, :b 2}
        {:a 23, :b 7}]]
  (match [x]
   [[a b c]]                               [a b c]
   [{:a a, :b 2}]                          {:a a}
   [{:a (a :guard #(and (integer? %)
                        (odd? %))), :b b}] {:a a, :b b}
   :else                                   :no-match))

But is it really intensional that guards have to deal with :clojure.core.match/not-found? In my opinion, in the example above all maps that are matched have integer values, so it seems plausible that I can have a guard that only accepts integers.



 Comments   
Comment by Tassilo Horn [ 17/Dec/14 7:34 AM ]

You can actually use that :clojure.core.match/not-found special value to make a kind of perverted map pattern that matches only if it doesn't match like so.

(match [{:a 1}]
  [{:b (a :guard #(identical? % :clojure.core.match/not-found))}] :yes
  :else                                                           :no)
;=> yes

But I guess (and hope) nobody relies on such a strange behavior.





[MATCH-65] cata matching Created: 23/Nov/12  Updated: 12/Dec/14

Status: Open
Project: core.match
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: David Nolen Assignee: David Nolen
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Dan Friedman's pattern matcher has a nice feature called cata-matching - allowing recursive matching from the match itself. Useful when writing compilers.



 Comments   
Comment by David Nolen [ 10/Dec/14 12:38 PM ]

Similar to function application except that if a function call throws a no match exception, catch and backtrack.

Comment by David Nolen [ 12/Dec/14 4:18 PM ]

Going to de-prioritize for now as matching on function applications delivers a lot of power as is.





[MATCH-101] Apparent regression for test sharing literals Created: 12/Dec/14  Updated: 12/Dec/14

Status: Open
Project: core.match
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Critical
Reporter: David Nolen Assignee: David Nolen
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Not sure when this one was introduced but literal tests appear to not share correctly and literals are needlessly retested.






Generated at Fri Dec 19 04:49:41 CST 2014 using JIRA 4.4#649-r158309.