From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: New library num-base-converters
Date: Tue, 15 Aug 2017 11:24:05 -0400 [thread overview]
Message-ID: <jwvtw18j1ss.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: alpine.DEB.2.20.1708151843560.21357@calancha-pc
>>> +(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."
>> Having a string as both input and output is a bad API, I think.
> It's better API than not having API at all; it provides me the flexibility
> to handle input as '0xff', '#xff' or 'ff'. Not that bad.
What do you mean by "handle"? It only lets you convert the string to
a string in a different base, which is rarely what you need.
Instead you will generally want to extract the number it represents,
then modify it a bit than turn it back into a string in a given base.
>> All one needs is basically to add a `base` arg to number-to-string
>> (there's already one for string-to-number).
> Then we are again limited to 2 < b < 16 bases.
No. We can similarly extend string-to-number to accept bases > 16.
If you want to provide it without changing Emacs's core, you can make it
a package that exports <pkg>-string-to-number and
<pkg>-number-to-string, but the API should separate the conversion from
a string to a number and back, rather than force you to conversions
between strings, which force you to do things like "baseN-to-dec, then
string-to-number, do something, then number-to-string, then
dec-to-baseN", which is just silly (and inefficient to boot).
Stefan
next prev parent reply other threads:[~2017-08-15 15:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-14 17:26 New library num-base-converters Tino Calancha
2017-08-14 17:48 ` Ted Zlatanov
2017-08-15 2:11 ` raman
2017-08-15 2:50 ` Tino Calancha
2017-08-15 5:25 ` Drew Adams
2017-08-15 6:35 ` Tino Calancha
2017-08-15 7:55 ` Stefan Monnier
2017-08-15 9:49 ` Tino Calancha
2017-08-15 15:24 ` Stefan Monnier [this message]
2017-08-15 13:40 ` Ted Zlatanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvtw18j1ss.fsf-monnier+gmane.emacs.devel@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).