Support underscores for mpz/mpq assignments from strings

Sergey B Kirpichev skirpichev at gmail.com
Fri Jun 11 03:47:08 UTC 2021


On Thu, Jun 10, 2021 at 07:58:32PM +0200, Marc Glisse wrote:
> There is nothing special about the underscore

The '_' is more common for computer languages.  E.g. PEP 515 lists
D, Perl, Rust, Java, Julia, Ruby...

> C++ seems to go for "'", etc.

Yes, there are exceptions, but few.  (Other examples I know - are more
exotic languages and use spaces.)

> If we add support for separators, we need to do it in a way that allows the
> user the specify the separator, either through the locale or through an argument.

The gmp already has a hardcoded support for separators (space).  I think
it might be ok to add a new one, unless mixing different separators will
introduce an ambiguity in syntax.  (Postel's law: ... be liberal in
what you accept from other.)

(BTW, I doubt that using the locale will allow '_'.)

> I don't know if mpz_inp_str is the right function to introduce this, I would
> expect to see it in gmp_*scanf first, but others would know better.

Yes, *scanf should be adapted, for consistency (updated version
attached).  I've started with a different API because it was used to
initialize mpz/mpq's in the gmpy2 Python extension
(https://github.com/aleaxit/gmpy/issues/210).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sep.patch
Type: text/x-diff
Size: 4149 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-discuss/attachments/20210611/248c2a34/attachment-0001.bin>


More information about the gmp-discuss mailing list