<< Back to previous view

[MATCH-4] Optimized pattern matching on deftype/record, POJOs Created: 04/Sep/11  Updated: 10/Apr/15

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: 1
Labels: None


 Description   
(match [x]
  [({:a 0 :b 1} :type Foo)] :a0
  ...)

:a and :b would be converted to field access, i.e. (.a x)

As with primitive array matching, we should do an instance check followed by hinted field access.

We should consider adopting the deftype/record syntax.



 Comments   
Comment by David Nolen [ 27/Oct/11 4:41 PM ]
(match [x]
  [^Foo {.-bar 5 .-baz 7}] :a0
  [^Foo {.-bar _ .-woz 8}] :a1
  :else :a2)

Given the recent ClojureScript property access discussions this seems like an acceptable syntax for high-performance property access.

Maybe:

(match [^Foo x]
  [{.-bar 5 .-baz 7}] :a0
  [{.-bar _ .-woz 8}] :a1
  :else :a2)

But probably not since then we should probably throw if someone tries to declare a different type in the row.

Comment by Ron Pressler [ 10/Aug/13 4:57 PM ]

Hi. Any plans on resolving this?

Comment by David Nolen [ 11/Aug/13 10:55 AM ]

I have no specific timeline, it will definitely be after 0.2.0, only focusing on bugs at the moment.

Comment by Leonardo Borges [ 08/Apr/15 2:12 AM ]

Is it worth me picking this up?

I've implemented a very rudimentary version of this that I'm using here: https://github.com/leonardoborges/imminent#pattern-matching

Would love to see this extended and officially supported though. Thoughts?

Comment by David Nolen [ 08/Apr/15 7:53 AM ]

Yes happy to see someone pick this up.

Comment by Leonardo Borges [ 08/Apr/15 9:00 PM ]

Excellent! Would you have any pointers/guidelines? If not, I'll just go from first principles using what's described in https://github.com/clojure/core.match/wiki/Advanced-usage#participating-in-pattern-matching

Comment by David Nolen [ 10/Apr/15 5:12 PM ]

Yeah the primary issue is just figuring out a good syntax for it. Once that's in place I don't think getting it working will be so hard.

Generated at Thu Jul 30 09:26:07 CDT 2015 using JIRA 4.4#649-r158309.