From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludovic.courtes@laas.fr (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: Exposing `scm_i_mem2number ()' Date: Wed, 08 Mar 2006 10:33:53 +0100 Organization: LAAS-CNRS Message-ID: <87u0a9xou6.fsf@laas.fr> References: <87d5holin9.fsf@laas.fr> <874q30z3nr.fsf@zagadka.de> <87zmkrfmtz.fsf@laas.fr> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1141810471 31302 80.91.229.2 (8 Mar 2006 09:34:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 8 Mar 2006 09:34:31 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Mar 08 10:34:30 2006 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FGv3j-0004qW-SN for guile-devel@m.gmane.org; Wed, 08 Mar 2006 10:34:20 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FGv3j-0001Jc-6b for guile-devel@m.gmane.org; Wed, 08 Mar 2006 04:34:19 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FGv3e-00015W-HE for guile-devel@gnu.org; Wed, 08 Mar 2006 04:34:14 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FGv3c-0000wB-4O for guile-devel@gnu.org; Wed, 08 Mar 2006 04:34:12 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FGv3b-0000w3-Pr for guile-devel@gnu.org; Wed, 08 Mar 2006 04:34:11 -0500 Original-Received: from [140.93.0.15] (helo=laas.laas.fr) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FGv6P-0007kS-Jo for guile-devel@gnu.org; Wed, 08 Mar 2006 04:37:05 -0500 Original-Received: by laas.laas.fr (8.13.1/8.13.4) with SMTP id k289Y3fK007595; Wed, 8 Mar 2006 10:34:09 +0100 (CET) Original-To: Marius Vollmer X-URL: http://www.laas.fr/~lcourtes/ X-Revolutionary-Date: 18 =?iso-8859-1?Q?Vent=F4se?= an 214 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEB1F5364 X-PGP-Key: http://www.laas.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: powerpc-unknown-linux-gnu Mail-Followup-To: Marius Vollmer , guile-devel@gnu.org In-Reply-To: <87zmkrfmtz.fsf@laas.fr> (Ludovic =?iso-8859-1?Q?Court=E8s's?= message of "Thu, 16 Feb 2006 14:35:36 +0100") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) X-Spam-Score: 0 () X-Scanned-By: MIMEDefang at CNRS-LAAS X-MIME-Autoconverted: from 8bit to quoted-printable by laas.laas.fr id k289Y3fK007595 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:5763 Archived-At: Hi, ludovic.courtes@laas.fr (Ludovic Court=E8s) writes: > libguile/ > > 2006-02-16 Ludovic Court=E8s > > * numbers.c (scm_i_mem2number): Renamed to > `scm_c_locale_string_to_number ()'. > Updated callers. > =20 > * numbers.h: Updated function declaration. > > * print.c: Updated callers. > > * read.c: Likewise. > > > doc/ref/ > > 2006-02-16 Ludovic Court=E8s > > * api-data.texi (Conversion): Documented > `scm_c_locale_string_to_number ()'. Below is an updated version of this patch. It basically augments the documentation of `scm_c_locale_string_to_number ()' to make it clear that the word `locale' is about encoding, _not_ number representation. While writing it, it occurred to me that R5RS does not make it clear whether `string->number' converts from a number's external representation or not. I.e., it is not clear whether the two following forms are equivalent: 1. (string->number str) 2. (with-input-from-string str read) I believe most implementations and users assume that they are but I couldn't find any evidence about it. Opinions? Thanks, Ludovic. --- orig/doc/ref/api-data.texi +++ mod/doc/ref/api-data.texi @@ -1031,6 +1031,18 @@ @code{string->number} returns @code{#f}. @end deffn =20 +@deffn {C Function} scm_c_locale_string_to_number (string, len, radix) +Like @code{scm_string_to_number ()}, return a number (a Scheme object) +whose representation is expressed by the given C string @var{string} +of size @var{len} octets (@var{string} does not need to be +null-terminated). @var{radix} must be of type @code{unsigned int}. + +Note that the word @code{locale} in the function name only means that +@var{string} is encoded using the current locale encoding. The number +representation itself, as a string, is locale-independent: it is the +@emph{external representation} of a number, as defined by R5RS +@inforef{External representation, , r5rs}. +@end deffn =20 @node Complex @subsubsection Complex Number Operations --- orig/libguile/numbers.c +++ mod/libguile/numbers.c @@ -2937,7 +2937,8 @@ enum t_radix {NO_RADIX=3D0, DUAL=3D2, OCT=3D8, DEC=3D10, HEX=3D16}; =20 SCM -scm_i_mem2number (const char* mem, size_t len, unsigned int default_radi= x) +scm_c_locale_string_to_number (const char* mem, size_t len, + unsigned int default_radix) { unsigned int idx =3D 0; unsigned int radix =3D NO_RADIX; @@ -3043,9 +3044,9 @@ else base =3D scm_to_unsigned_integer (radix, 2, INT_MAX); =20 - answer =3D scm_i_mem2number (scm_i_string_chars (string), - scm_i_string_length (string), - base); + answer =3D scm_c_locale_string_to_number (scm_i_string_chars (string), + scm_i_string_length (string), + base); scm_remember_upto_here_1 (string); return answer; } --- orig/libguile/numbers.h +++ mod/libguile/numbers.h @@ -215,7 +215,8 @@ SCM_API int scm_print_real (SCM sexp, SCM port, scm_print_state *pstate)= ; SCM_API int scm_print_complex (SCM sexp, SCM port, scm_print_state *psta= te); SCM_API int scm_bigprint (SCM exp, SCM port, scm_print_state *pstate); -SCM_API SCM scm_i_mem2number (const char *mem, size_t len, unsigned int = radix); +SCM_API SCM scm_c_locale_string_to_number (const char *mem, size_t len, + unsigned int radix); SCM_API SCM scm_string_to_number (SCM str, SCM radix); SCM_API SCM scm_bigequal (SCM x, SCM y); SCM_API SCM scm_real_equalp (SCM x, SCM y); --- orig/libguile/print.c +++ mod/libguile/print.c @@ -153,8 +153,8 @@ =20 #ifdef GUILE_DEBUG /* Used for debugging purposes */ =20 -SCM_DEFINE (scm_current_pstate, "current-pstate", 0, 0, 0,=20 - (), +SCM_DEFINE (scm_current_pstate, "current-pstate", 0, 0, 0, + (void), "Return the current-pstate -- the car of the\n" "@code{print_state_pool}. @code{current-pstate} is only\n" "included in @code{--enable-guile-debug} builds.") @@ -327,7 +327,7 @@ if (len =3D=3D 0 || str[0] =3D=3D '\'' || str[0] =3D=3D '`' || str[0] = =3D=3D ',' || quote_keywordish_symbol (str, len) || (str[0] =3D=3D '.' && len =3D=3D 1) - || scm_is_true (scm_i_mem2number(str, len, 10))) + || scm_is_true (scm_c_locale_string_to_number (str, len, 10))) { scm_lfwrite ("#{", 2, port); weird =3D 1; --- orig/libguile/read.c +++ mod/libguile/read.c @@ -506,7 +506,8 @@ * does only consist of octal digits. Finally, it should be * checked whether the resulting fixnum is in the range of * characters. */ - p =3D scm_i_mem2number (scm_i_string_chars (*tok_buf), j, 8); + p =3D scm_c_locale_string_to_number (scm_i_string_chars (*tok_buf= ), + j, 8); if (SCM_I_INUMP (p)) return SCM_MAKE_CHAR (SCM_I_INUM (p)); } @@ -644,7 +645,7 @@ /* Shortcut: Detected symbol '+ or '- */ goto tok; =20 - p =3D scm_i_mem2number (scm_i_string_chars (*tok_buf), j, 10); + p =3D scm_c_locale_string_to_number (scm_i_string_chars (*tok_buf)= , j, 10); if (scm_is_true (p)) return p; if (c =3D=3D '#') _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel