Hi Chris,

Nice to see you on the list.

While this is definitely off-topic, I trust I might be given license by the list's few remaining readers to point out that the match-case construct is for _structural_ pattern matching. As I wrote in the latest Nutshell: "Resist the temptation to use match unless there is a need to analyse the _structure_ of an object."

I don't believe it's accidental that match-case sequence patterns won't match str, bytes or bytearrray objects - regexen are the tool already optimised for that purpose, so it's quite impressive that you are managing to approach the same level of performance!

Kind regards,
Steve


On Wed, 2 Aug 2023 at 18:26, Christian Tismer-Sperling <tismer@stackless.com> wrote:
On 02.08.23 18:30, Paul Moore wrote:
> On Wed, 2 Aug 2023 at 15:24, Stephen J. Turnbull
> <turnbull.stephen.fw@u.tsukuba.ac.jp
> <mailto:turnbull.stephen.fw@u.tsukuba.ac.jp>> wrote:
>
>     Partly because that's where the other discussants are (the network
>     externality is undeniably powerful), and partly (I believe) because
>     effective use of email is a skill that requires effort to acquire.
>     Popular mail clients are designed to be popular, not to make that
>     expertise easy to acquire and exercise.  Clunky use of email makes
>     lists much less pleasant for everyone than they could be.
>
>     I guess that's sad (I am, after all, a GNU Mailman developer), but
>     it's reality.
>
>
> Personally, I'm sad because some people whose contributions I enjoy (you
> being one of them :-)) didn't move to Discourse. But like you say, it's
> how things are.
>
> Christian - you can make named constants using class attributes (or an
> enum):
>
> class A:
>      M = "M"
>
> match seq:
>      case A.M, A.M, A.M, A.M, *r:
>          return 4*1000, r
>
> Basically, the "names are treated as variables to assign to" rule
> doesn't apply to attributes.
>
> I'm not sure how helpful that is (it's not particularly *shorter*) but I
> think the idea was that most uses of named constants in a match
> statement would be enums or module attributes. And compromises had to be
> made.
>
> Cheers,
> Paul

Thanks a lot, everybody!

I have tried a lot now, using classes which becomes more readable
but - funnily - slower! Using the clumsy if-guards felt slow but isn't.

Then I generated functions even, with everything as constants,
and now the SPM version in fact out-performs the regex slightly!

But at last, I found an even faster and correct algorithm
by a different approach, which ends now this story :)

Going to the Discourse tite, now.

Cheers -- Chris
--
Christian Tismer-Sperling    :^)   tismer@stackless.com
Software Consulting          :     http://www.stackless.com/
Strandstraße 37              :     https://github.com/PySide
24217 Schönberg              :     GPG key -> 0xFB7BEE0E
phone +49 173 24 18 776  fax +49 (30) 700143-0023

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/OFLAU34KWAKREKG4H2M5GES3PGT6VBAU/
Code of Conduct: http://python.org/psf/codeofconduct/