[Cython] Feature Request: expand list/tuple in 'if (... in ...):' ...

Christian Inci chris.pcguy.inci at gmail.com
Thu Jan 24 16:19:12 CET 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/24/2013 03:44 PM, Dag Sverre Seljebotn wrote:
> How do you know that INT_TUPLE isn't reassigned to something else?

On 01/24/2013 03:49 PM, Stefan Behnel wrote:
> This is not an optimisation as it might render the code incorrect. How can
> Cython know that you'll never change INT_TUPLE at runtime?

A good point. What's about something like final or const?

> However, if you use a literal list or tuple in place, this already works,
> i.e. the first example is equivalent to
> 
>     if j in (0x66, 0x67, 0x2e,
>              0x36, 0x3e, 0x26, 0x64,
>              0x65, 0xf2, 0xf3, 0xf0):
> 
> You actually get a C switch statement for it.

Thanks, this actually works. :-)

> 
> If you prefer keeping the set of integer values at a separate place, this
> should work:
> 
>     DEF INT_TUPLE = (0x66, 0x67, 0x2e,
>                      0x36, 0x3e, 0x26, 0x64,
>                      0x65, 0xf2, 0xf3, 0xf0)
> 
> (mind the upper case "DEF").

But this doesn't work. That's why I'm using 'cdef tuple'.

According to 'http://docs.cython.org/src/userguide/language_basics.html#compile-time-definitions', this will only work using int, long, float or str.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRAVDuAAoJEDfL/pqB6n6NsCYP/1HgWbMRuSi4o5o0gIxeSpfl
hkesrLlKe3sodTsWt3cSPGWBg5Y1pq25SUSCLCNssJruXTZ66FCTyMffc3TpEuei
PUSKq+byFplYEmCMPEm1l2z2vBI4+c5JggcXwDLlmp9RR6ZWXft0tb6fg/4Tqwyf
76/l6jrJiI7DImeJwHKDfSs1bHWCIZYPIjQWkeC42kETFG1G+U/L7tfZ8+7oq0pN
fXhRn+XK2ax3iMsswzgIBAuyywASvT2uqMI3/G+MnD7tCiRFZkzILEa3+igxqMYN
H/C9N33XLPZ1UulX40c88LHe1i2fpLvu1IvWoYc42Tszkd8Wd+uASs78b1puFTk+
jeeBLQkGbMle+eCXWQLfnSdmvvn3yYdE1UgVxQ4RXONjol9PSI1r86xn2V97phmW
C/t4r6174hv49wAG1MoMVwXOUJH3ylEBz2qJFq06nwKAU7891dd9O1tXvoVsTihe
NYDk6zflZlPZi7FUMs66S//rYYrXY/ZkA3/NhD9Krbd/Z1cVFTN1J/ynoccMx8dY
pjRz9A+oIzXw/6kvITmGx22iKZRSlhLYe32ZT1qiGk8N1nGAvlaVIqK9mpeQhECX
5CEPSj4+t6T7th7Nh/fMOqJomf0AfzCsuz4QYlYQ8Y+7zfwuOnC8AkkoIid6ac1e
M4vXi93fgnp64RpxKkxS
=Lgq1
-----END PGP SIGNATURE-----


More information about the cython-devel mailing list