core.match

Optimized pattern matching on deftype/record, POJOs

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • 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.

Activity

David Nolen made changes -
Field Original Value New Value
Priority Major [ 3 ] Minor [ 4 ]
Hide
David Nolen added a comment - - edited
(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.

Show
David Nolen added a comment - - edited
(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.
David Nolen made changes -
Priority Minor [ 4 ] Major [ 3 ]
David Nolen made changes -
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.
{code}
(match [x]
  [({:a 0 :b 1} :type Foo)] :a0
  ...)
{code}

: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.
Hide
Ron Pressler added a comment -

Hi. Any plans on resolving this?

Show
Ron Pressler added a comment - Hi. Any plans on resolving this?
Hide
David Nolen added a comment -

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

Show
David Nolen added a comment - I have no specific timeline, it will definitely be after 0.2.0, only focusing on bugs at the moment.
Hide
Leonardo Borges added a comment -

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?

Show
Leonardo Borges added a comment - 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?
Hide
David Nolen added a comment -

Yes happy to see someone pick this up.

Show
David Nolen added a comment - Yes happy to see someone pick this up.
Hide
Leonardo Borges added a comment -

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

Show
Leonardo Borges added a comment - 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
Hide
David Nolen added a comment -

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.

Show
David Nolen added a comment - 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.

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated: