scsh-users
[Top] [All Lists]

string->number fails for "1e2"

To: scsh-users@scsh.net
Subject: string->number fails for "1e2"
From: Emilio Lopes <eclig@gmx.net>
Date: Wed, 01 Nov 2006 19:05:33 +0100
Cancel-lock: sha1:JNCLZ0AfQgkQJPxulRh8RwngtQc=
List-id: <scsh-users.list-id.scsh.net>
Organization: The Church of Emacs
Sender: news <news@sea.gmane.org>
As stated in the subject line:

   Welcome to scsh 0.6.7 (R6RS)
   Type ,? for help.
   > (string->number "1e2")
   #f

This particular example comes from R5RS [1].

But:

   > (string->number "1.e2")
   100.

The patch bellow, taken verbatim from Scheme48, seems to fix this
problem.

Footnotes: 
[1]  
http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-9.html#%_idx_352

diff -c "/home/ecl/scsh/scsh-0.6.7/scheme/rts/numio.scm.~1~" 
"/home/ecl/scsh/scsh-0.6.7/scheme/rts/numio.scm"
*** /home/ecl/scsh/scsh-0.6.7/scheme/rts/numio.scm.~1~  Tue Sep 14 13:44:58 1999
--- /home/ecl/scsh/scsh-0.6.7/scheme/rts/numio.scm      Tue Oct 17 16:16:06 2006
***************
*** 121,126 ****
--- 121,134 ----
                             #f)        ;inexact
                            ((char=? (string-ref string pos) #\#)
                             #f)
+                           ((and (= radix 10)
+                                 (case (char-downcase (string-ref string pos))
+                                   ;; One day, we have to include #\s #\f #\d 
#\l.
+                                   ;; We don't now because STRING->FLOAT 
actually does the
+                                   ;; wrong thing for these currently, so we'd 
rather barf.
+                                   ((#\e) #t)
+                                   (else #f)))
+                            #f)
                            (else (loop (+ pos 1))))))))))))
  
  (define-generic really-string->number &really-string->number)

Diff finished.  Tue Oct 17 17:22:12 2006

<Prev in Thread] Current Thread [Next in Thread>