From: ludovic.courtes@laas.fr (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: Exposing `scm_i_mem2number ()'
Date: Wed, 08 Mar 2006 10:33:53 +0100 [thread overview]
Message-ID: <87u0a9xou6.fsf@laas.fr> (raw)
In-Reply-To: <87zmkrfmtz.fsf@laas.fr> (Ludovic Courtès's message of "Thu, 16 Feb 2006 14:35:36 +0100")
Hi,
ludovic.courtes@laas.fr (Ludovic Courtès) writes:
> libguile/
>
> 2006-02-16 Ludovic Courtès <ludovic.courtes@laas.fr>
>
> * numbers.c (scm_i_mem2number): Renamed to
> `scm_c_locale_string_to_number ()'.
> Updated callers.
>
> * numbers.h: Updated function declaration.
>
> * print.c: Updated callers.
>
> * read.c: Likewise.
>
>
> doc/ref/
>
> 2006-02-16 Ludovic Courtès <ludovic.courtes@laas.fr>
>
> * 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
+@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
@node Complex
@subsubsection Complex Number Operations
--- orig/libguile/numbers.c
+++ mod/libguile/numbers.c
@@ -2937,7 +2937,8 @@
enum t_radix {NO_RADIX=0, DUAL=2, OCT=8, DEC=10, HEX=16};
SCM
-scm_i_mem2number (const char* mem, size_t len, unsigned int default_radix)
+scm_c_locale_string_to_number (const char* mem, size_t len,
+ unsigned int default_radix)
{
unsigned int idx = 0;
unsigned int radix = NO_RADIX;
@@ -3043,9 +3044,9 @@
else
base = scm_to_unsigned_integer (radix, 2, INT_MAX);
- answer = scm_i_mem2number (scm_i_string_chars (string),
- scm_i_string_length (string),
- base);
+ answer = 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 *pstate);
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 @@
#ifdef GUILE_DEBUG /* Used for debugging purposes */
-SCM_DEFINE (scm_current_pstate, "current-pstate", 0, 0, 0,
- (),
+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 == 0 || str[0] == '\'' || str[0] == '`' || str[0] == ','
|| quote_keywordish_symbol (str, len)
|| (str[0] == '.' && len == 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 = 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 = scm_i_mem2number (scm_i_string_chars (*tok_buf), j, 8);
+ p = 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;
- p = scm_i_mem2number (scm_i_string_chars (*tok_buf), j, 10);
+ p = scm_c_locale_string_to_number (scm_i_string_chars (*tok_buf), j, 10);
if (scm_is_true (p))
return p;
if (c == '#')
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
next prev parent reply other threads:[~2006-03-08 9:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-15 15:57 Exposing `scm_i_mem2number ()' Ludovic Courtès
2006-02-15 21:57 ` Marius Vollmer
2006-02-16 12:17 ` Tomas Zerolo
2006-02-16 13:35 ` Ludovic Courtès
2006-03-08 9:33 ` Ludovic Courtès [this message]
2006-03-16 10:07 ` Ludovic Courtès
2006-03-17 0:58 ` Kevin Ryde
2006-03-17 9:01 ` Ludovic Courtès
2006-03-21 0:53 ` Kevin Ryde
2006-02-15 22:11 ` Kevin Ryde
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/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87u0a9xou6.fsf@laas.fr \
--to=ludovic.courtes@laas.fr \
--cc=guile-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.
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).