[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New library num-base-converters

From: Ted Zlatanov
Subject: Re: New library num-base-converters
Date: Tue, 15 Aug 2017 09:40:04 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

On Tue, 15 Aug 2017 03:55:19 -0400 Stefan Monnier <address@hidden> wrote: 

>> +(defun nbc-number-base-converter (num base-in base-out)
>> +  "Translate NUM, a string representing an integer, to a different base.
>> +BASE-IN, an integer, is the basis of the input NUM.
>> +BASE-OUT, an integer, is the basis to display NUM."

SM> Having a string as both input and output is a bad API, I think.

It's OK for a parser :)

SM> All one needs is basically to add a `base` arg to number-to-string
SM> (there's already one for string-to-number).

I think that's a good improvement as well, especially if it works for
larger bases and errors out if the base is out of range.

On Tue, 15 Aug 2017 18:49:45 +0900 (JST) Tino Calancha <address@hidden> wrote: 

TC> It's better API than not having API at all; it provides me the flexibility
TC> to handle input as '0xff', '#xff' or 'ff'.  Not that bad.

So one approach is to write your library so it parses and converts in
one shot, as it does today. This limits its utility and reusability.

The other approach is to follow Stefan's suggestion to improve
`number-to-string' and `string-to-number' in the core, and then to add
to your library a dedicated parser that can accept all the possible
inputs you want. So your library would be that parser plus glue to
`number-to-string' and `string-to-number'. Maybe also a fallback for
backwards compatibility if the core `number-to-string' and
`string-to-number' are less capable. I think that solution would benefit
Emacs developers and users the most, long-term.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]