Re: Some pattern annoyance

Barry <[email protected]> Wed, 2 Aug 2023 12:23:50 +0100
Newsgroups gmane.comp.python.devel
Message-ID <[email protected]>
--===============2548574900471338305==
Content-Type: multipart/alternative;
 boundary=Apple-Mail-DE92CA7E-E254-4BFB-8581-AB740822CFA4
Content-Transfer-Encoding: 7bit


--Apple-Mail-DE92CA7E-E254-4BFB-8581-AB740822CFA4
Content-Type: text/plain;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable



> On 2 Aug 2023, at 12:03, Christian Tismer-Sperling <[email protected]> w=
rote:
>=20
> =EF=BB=BFHi folks,
>=20
> I just used Structural Pattern Matching quite intensively and I'm
> pretty amazed of the new possibilities.
>=20
> But see this code, trying to implement Mark Pilgrim's regex
> algorithm for roman literals with SPM:
>=20
> With constants, I can write
>=20
>    match seq:
>        case "M", "M", "M", "M", *r:
>            return 4 * 1000, r
>=20
> But if I want to use abbreviations by assignment, this is no longer
> possible, and I have to write something weird like:
>=20
>    M =3D "M"
>    match seq:
>        case a, b, c, d, *r if M =3D=3D a =3D=3D b =3D=3D c =3D=3D d:
>            return 4 * 1000, r
>=20
> So what is missing seems to be a notion of const-ness, which
> could be dynamically deduced. Am I missing something?

Try asking for help at https://discuss.python.org/
This list is not for help or ideas, also its basically dead.

Barry
>=20
> --=20
> Christian Tismer-Sperling    :^)   [email protected]
> Software Consulting          :     http://www.stackless.com/
> Strandstra=C3=9Fe 37              :     https://github.com/PySide
> 24217 Sch=C3=B6nberg              :     GPG key -> 0xFB7BEE0E
> phone +49 173 24 18 776  fax +49 (30) 700143-0023
> _______________________________________________
> Python-Dev mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at https://mail.python.org/archives/list/python-dev@pytho=
n.org/message/5MKBWCSVYZKR3S7OVY6KBF6FE7WYB5LC/
> Code of Conduct: http://python.org/psf/codeofconduct/

--Apple-Mail-DE92CA7E-E254-4BFB-8581-AB740822CFA4
Content-Type: text/html;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D=
utf-8"></head><body dir=3D"auto"><div dir=3D"ltr"></div><div dir=3D"ltr"><br=
></div><div dir=3D"ltr"><br><blockquote type=3D"cite">On 2 Aug 2023, at 12:0=
3, Christian Tismer-Sperling &lt;[email protected]&gt; wrote:<br><br></bl=
ockquote></div><blockquote type=3D"cite"><div dir=3D"ltr">=EF=BB=BF<span>Hi f=
olks,</span><br><span></span><br><span>I just used Structural Pattern Matchi=
ng quite intensively and I'm</span><br><span>pretty amazed of the new possib=
ilities.</span><br><span></span><br><span>But see this code, trying to imple=
ment Mark Pilgrim's regex</span><br><span>algorithm for roman literals with S=
PM:</span><br><span></span><br><span>With constants, I can write</span><br><=
span></span><br><span> &nbsp;&nbsp;&nbsp;match seq:</span><br><span> &nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case "M", "M", "M", "M", *r:</span><br><s=
pan> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retur=
n 4 * 1000, r</span><br><span></span><br><span>But if I want to use abbrevia=
tions by assignment, this is no longer</span><br><span>possible, and I have t=
o write something weird like:</span><br><span></span><br><span> &nbsp;&nbsp;=
&nbsp;M =3D "M"</span><br><span> &nbsp;&nbsp;&nbsp;match seq:</span><br><spa=
n> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case a, b, c, d, *r if M =3D=3D=
 a =3D=3D b =3D=3D c =3D=3D d:</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 4 * 1000, r</span><br><span></s=
pan><br><span>So what is missing seems to be a notion of const-ness, which</=
span><br><span>could be dynamically deduced. Am I missing something?</span><=
br></div></blockquote><div><br></div><div>Try asking for help at&nbsp;<a hre=
f=3D"https://discuss.python.org/">https://discuss.python.org/</a></div><div>=
This list is not for help or ideas, also its basically dead.</div><div><br><=
/div><div>Barry</div><blockquote type=3D"cite"><div dir=3D"ltr"><span></span=
><br><span>-- </span><br><span>Christian Tismer-Sperling &nbsp;&nbsp;&nbsp;:=
^) &nbsp;&nbsp;[email protected]</span><br><span>Software Consulting &nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;=
http://www.stackless.com/</span><br><span>Strandstra=C3=9Fe 37 &nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nb=
sp;&nbsp;&nbsp;https://github.com/PySide</span><br><span>24217 Sch=C3=B6nber=
g &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;: &nbsp;&nbsp;&nbsp;&nbsp;GPG key -&gt; 0xFB7BEE0E</span><br><span>phone=
 +49 173 24 18 776 &nbsp;fax +49 (30) 700143-0023</span><br><span>__________=
_____________________________________</span><br><span>Python-Dev mailing lis=
t -- [email protected]</span><br><span>To unsubscribe send an email to p=
[email protected]</span><br><span>https://mail.python.org/mailman3/=
lists/python-dev.python.org/</span><br><span>Message archived at https://mai=
l.python.org/archives/list/[email protected]/message/5MKBWCSVYZKR3S7OVY6=
KBF6FE7WYB5LC/</span><br><span>Code of Conduct: http://python.org/psf/codeof=
conduct/</span><br></div></blockquote></body></html>=

--Apple-Mail-DE92CA7E-E254-4BFB-8581-AB740822CFA4--

--===============2548574900471338305==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline