From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.devel Subject: RE: New library num-base-converters Date: Tue, 15 Aug 2017 15:35:10 +0900 (JST) Message-ID: References: <87r2wem462.fsf@lifelogs.com> <84387000-0545-4a51-8644-772b6b53165c@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-833780108-1502778913=:14915" X-Trace: blaine.gmane.org 1502778931 17489 195.159.176.226 (15 Aug 2017 06:35:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 15 Aug 2017 06:35:31 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: raman , Emacs developers , Tino Calancha To: Drew Adams Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 15 08:35:26 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dhVRg-0003yF-A1 for ged-emacs-devel@m.gmane.org; Tue, 15 Aug 2017 08:35:20 +0200 Original-Received: from localhost ([::1]:42137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhVRm-0005zk-NI for ged-emacs-devel@m.gmane.org; Tue, 15 Aug 2017 02:35:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhVRf-0005yV-F0 for emacs-devel@gnu.org; Tue, 15 Aug 2017 02:35:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhVRb-0001SW-Bo for emacs-devel@gnu.org; Tue, 15 Aug 2017 02:35:19 -0400 Original-Received: from mail-pg0-x230.google.com ([2607:f8b0:400e:c05::230]:37728) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dhVRb-0001RZ-52 for emacs-devel@gnu.org; Tue, 15 Aug 2017 02:35:15 -0400 Original-Received: by mail-pg0-x230.google.com with SMTP id y129so660590pgy.4 for ; Mon, 14 Aug 2017 23:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=HTKY7xd7xa825Qp5NFIrkxo2H60jZrMplLJlMpb2R0k=; b=Oh69mLwrZO+e536mnWn7pp5Y5n17MmVNA8RNzbjQeOiiXku7RV4kwzGysjOv++obmo q6caMinkVM2rvLx55YpCYeVeB0HFv8FMzUFCTJLTvHKWVR4+vp1EIM/vEl2oclhHIqxg crEmN1wijlBCKAkBlhonc4VKQcxCqRXDpdeZOG2cQMniJvaREG2Ey5SGutSdyxcMRW72 +01NoMAxru4BNVN8KStnx5gCaVh9DPVv0lA413sKXMt7ojNNnZrGYaqibMEA2i0VMJbv ybZSNclgjIenpqxjXcPEeHUYZYbOpl1KrU3DTZP7eoj1Z9W/I9TwLIKnfo0NfTH5kwY/ HmcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=HTKY7xd7xa825Qp5NFIrkxo2H60jZrMplLJlMpb2R0k=; b=O+YiW3JHbpmW4y+uThpokKPbleRoEpJIY02tT+QLGBDq+mJVcMQbrGUak30N4Ll+6f HpolgQ85AlyydCaJ8P3reFs17SkdaOySnCmTck/0xfiNB87E8m47oBIbu5ChNZ0Qfauw mIgsdxhtuwOf3VVklZXZNPbvRrcXXbynio95QVjf09aAlgSEKzbf+XsFramdJEY7KJgc RhYmhcswH65ks7TZJ9B7MEOmPxAlJfMJ/77F95P/ZPvT2dsR2oxpwL8r0GxMwbKrUmDg GfPwvwBP1n23ISurtKBXBgV9NueuJCD51cZKpcq4aihoFOFthJhLY7b548X7+CHmIddQ EtAA== X-Gm-Message-State: AHYfb5iaIIF8e5703ujSlfateL1zW35Xf19Yvf8H8ZcocfGouPWdsddw 6VgOjmaBuqg9vQ== X-Received: by 10.98.55.134 with SMTP id e128mr4661136pfa.176.1502778914047; Mon, 14 Aug 2017 23:35:14 -0700 (PDT) Original-Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id y4sm18555120pfd.116.2017.08.14.23.35.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 23:35:13 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: <84387000-0545-4a51-8644-772b6b53165c@default> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::230 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:217558 Archived-At: --8323329-833780108-1502778913=:14915 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8BIT On Mon, 14 Aug 2017, Drew Adams wrote: >> One point of this library is the convenience of not having to >> know anything about neither calculator.el nor calc.el to get >> the answer with easy. >> >> Every Emacs user will understand the following: >> M-x nbc-hex2dec ff RET >> "ff hexadecimal = 255 decimal" >> >> M-: (nbc-oct2dec "644") RET >> => 420 >> >> ;; Or just `hex2dec' and `oct2dec' if you customize >> ;; `nbc-define-aliases' to non-nil. > > (format "%d" #xff) ; hex to decimal > --> "255" > > (format "%x" 255) ; decimal to hex > --> "ff" > > (format "%d" #o644) ; octal to decimal > --> "420" > > (format "%o" 420) ; decimal to octal > --> "644" For an user familiar with the Emacs '#' read syntaxis might be OK. But for the average user, it's better to accept more input formats: (nbc-hex2dec "#xff") "255" (nbc-hex2dec "ff") "255" (nbc-hex2dec "0xff") "255" > And didn't Pascal B. point this out in the thread previously cited? > > (format "#8r%o #10r%d #16r%x" 42 42 42) > --> "#8r52 #10r42 #16r2a" *) cannot be called interactively. *) This covers the base range 2 <= b <= 16. Even worse, it silently returns a wrong result for b > 16: (format "#16r%x" 42) "#16r2a" (format "#17r%x" 42) "#17r2a" (format "#37r%x" 42) "#37r2a" Compare with: (nbc-number-base-converter "42" 10 16) "2A" (nbc-number-base-converter "42" 10 17) "28" (nbc-number-base-converter "42" 10 37) ;; Signal error: Base ‘b’ must satisfy 2 <= b <= 36: base-in ‘10’ base-out ‘37’ --8323329-833780108-1502778913=:14915--