From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nick Roberts Newsgroups: gmane.emacs.devel Subject: string-to-number Date: Thu, 17 Nov 2005 17:20:02 +1300 Message-ID: <17276.1266.685618.602203@kahikatea.snap.net.nz> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1132201245 2959 80.91.229.2 (17 Nov 2005 04:20:45 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 17 Nov 2005 04:20:45 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 17 05:20:43 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EcbFx-000888-F8 for ged-emacs-devel@m.gmane.org; Thu, 17 Nov 2005 05:20:17 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EcbFw-0007MB-TK for ged-emacs-devel@m.gmane.org; Wed, 16 Nov 2005 23:20:16 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EcbFh-0007M6-E1 for emacs-devel@gnu.org; Wed, 16 Nov 2005 23:20:01 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EcbFf-0007Lr-BF for emacs-devel@gnu.org; Wed, 16 Nov 2005 23:20:00 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EcbFf-0007Lo-6J for emacs-devel@gnu.org; Wed, 16 Nov 2005 23:19:59 -0500 Original-Received: from [202.37.101.8] (helo=viper.snap.net.nz) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EcbFf-00014y-0w for emacs-devel@gnu.org; Wed, 16 Nov 2005 23:19:59 -0500 Original-Received: from kahikatea.snap.net.nz (p190-tnt1.snap.net.nz [202.124.110.190]) by viper.snap.net.nz (Postfix) with ESMTP id 18745731148 for ; Thu, 17 Nov 2005 17:19:53 +1300 (NZDT) Original-Received: by kahikatea.snap.net.nz (Postfix, from userid 500) id 11C3D8422; Thu, 17 Nov 2005 17:20:03 +1300 (NZDT) Original-To: emacs-devel@gnu.org X-Mailer: VM 7.19 under Emacs 22.0.50.24 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:46137 Archived-At: Currently string-to-number gives 0 for a non-number: (string-to-number "a")^J 0 but (string-to-number "0")^J 0 gives the same result. So what is a simple test for whether a string represents a number or not? If there isn't one, how about: (string-to-number "a")^J nil Of course this means an error is generated if you try to do arithmetic with a non-number, but I think that this is appropriate and preferable to taking a value of 0. Nick *** data.c 31 Oct 2005 00:56:53 +1300 1.256 --- data.c 17 Nov 2005 16:28:28 +1300 *************** *** 2466,2472 **** register unsigned char *p; register int b; int sign = 1; ! Lisp_Object val; CHECK_STRING (string); --- 2466,2472 ---- register unsigned char *p; register int b; int sign = 1; ! Lisp_Object val = Qnil; CHECK_STRING (string); *************** *** 2506,2514 **** if (digit < 0) break; v = v * b + digit; } ! val = make_fixnum_or_float (sign * v); } return val; --- 2506,2515 ---- if (digit < 0) break; v = v * b + digit; + val = Qt; } ! if (!NILP (val)) val = make_fixnum_or_float (sign * v); } return val;