From: lee.crabtree
Subject: numerical string predicates
Date: 
Message-ID: <c5485e4e-5b0c-4d7b-951e-3a06c7e42e21@b1g2000pra.googlegroups.com>
Is there a way to tell if a string as a whole can be parsed as a
number?  In the specific case I'm working on, I only need to make sure
a string can be parsed as an integer, but I have no doubt that there's
a general purpose solution.

I know about PARSE-INTEGER, but the main problem is that it just bombs
out if there's a problem, and it returns success as soon as it finds
an integer value.  That is,

(parse-integer "1A")

returns successfully, and instead of NIL,

(parse-integer "A1")

signals a SIMPLE-PARSE-ERROR.

My attempt at figuring this out returned T no matter what was passed
to it, even NIL.  Here's where I got:

(defun parseable-integer-p (string-num)
  (handler-case
   (progn
     (parse-integer string-num :junk-allowed nil)
     t)
   (system::simple-parse-error (c)
		(declare (ignore c))
		nil)))

No matter what I pass into that, T is returned.  I'm using CLISP
version 2.43.

Any ideas?

Lee Crabtree

From: ········@gmail.com
Subject: Re: numerical string predicates
Date: 
Message-ID: <cceffdcd-e9d4-4415-a409-3c4673f37e1b@d27g2000prf.googlegroups.com>
On Dec 13, 7:51 pm, "lee.crabtree" <············@gmail.com> wrote:
> Is there a way to tell if a string as a whole can be parsed as a
> number?  In the specific case I'm working on, I only need to make sure
> a string can be parsed as an integer, but I have no doubt that there's
> a general purpose solution.

For integers I think the simplest way would be just (every #'digit-
char-p "somestring"). For a more general case maybe:
(defun string-number-p (string)
  (multiple-value-bind (potential-number read-length) (read-from-
string string)
    (and (= read-length (length string))
         (numberp potential-number))))
From: Barry Margolin
Subject: Re: numerical string predicates
Date: 
Message-ID: <barmar-70B74F.23062913122007@comcast.dca.giganews.com>
In article 
<····································@d27g2000prf.googlegroups.com>,
 ········@gmail.com wrote:

> On Dec 13, 7:51 pm, "lee.crabtree" <············@gmail.com> wrote:
> > Is there a way to tell if a string as a whole can be parsed as a
> > number?  In the specific case I'm working on, I only need to make sure
> > a string can be parsed as an integer, but I have no doubt that there's
> > a general purpose solution.
> 
> For integers I think the simplest way would be just (every #'digit-
> char-p "somestring").

The definition I've always heard for "integers" includes negative 
numbers.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Geoffrey Summerhayes
Subject: Re: numerical string predicates
Date: 
Message-ID: <1fd27c36-2263-49e1-a113-b3fa286f208b@i29g2000prf.googlegroups.com>
On Dec 13, 1:51 pm, "lee.crabtree" <············@gmail.com> wrote:
> Is there a way to tell if a string as a whole can be parsed as a
> number?  In the specific case I'm working on, I only need to make sure
> a string can be parsed as an integer, but I have no doubt that there's
> a general purpose solution.
>
> I know about PARSE-INTEGER, but the main problem is that it just bombs
> out if there's a problem, and it returns success as soon as it finds
> an integer value.  That is,
>
> (parse-integer "1A")
>
> returns successfully, and instead of NIL,

That should have signaled a parse error.

> (parse-integer "A1")
>
> signals a SIMPLE-PARSE-ERROR.
>
> My attempt at figuring this out returned T no matter what was passed
> to it, even NIL.  Here's where I got:
>
> (defun parseable-integer-p (string-num)
>   (handler-case
>    (progn
>      (parse-integer string-num :junk-allowed nil)
>      t)
>    (system::simple-parse-error (c)
>                 (declare (ignore c))
>                 nil)))
>
> No matter what I pass into that, T is returned.  I'm using CLISP
> version 2.43.

Weird, what platform?...

[6]> (loop for x in '("1A" "A1" "45" "65 " " 99 " "3.141519" "45
test")
      collect (ignore-errors (parse-integer x)))
(NIL NIL 45 65 99 NIL NIL)
[7]> (lisp-implementation-version)
"2.43 (2007-11-18) (built on stnt067 [192.168.0.1])"
[8]>

---
Geoff
From: Rainer Joswig
Subject: Re: numerical string predicates
Date: 
Message-ID: <joswig-3BB943.20011513122007@news-europe.giganews.com>
In article 
<····································@b1g2000pra.googlegroups.com>,
 "lee.crabtree" <············@gmail.com> wrote:

> Is there a way to tell if a string as a whole can be parsed as a
> number?  In the specific case I'm working on, I only need to make sure
> a string can be parsed as an integer, but I have no doubt that there's
> a general purpose solution.
> 
> I know about PARSE-INTEGER, but the main problem is that it just bombs
> out if there's a problem, and it returns success as soon as it finds
> an integer value.  That is,
> 
> (parse-integer "1A")
> 
> returns successfully, and instead of NIL,
> 
> (parse-integer "A1")
> 
> signals a SIMPLE-PARSE-ERROR.
> 
> My attempt at figuring this out returned T no matter what was passed
> to it, even NIL.  Here's where I got:
> 
> (defun parseable-integer-p (string-num)
>   (handler-case
>    (progn
>      (parse-integer string-num :junk-allowed nil)
>      t)
>    (system::simple-parse-error (c)
> 		(declare (ignore c))
> 		nil)))
> 
> No matter what I pass into that, T is returned.  I'm using CLISP
> version 2.43.
> 
> Any ideas?
> 
> Lee Crabtree

Works for me in CLISP 2.41 on an Intel Mac.

-- 
http://lispm.dyndns.org/
From: lee.crabtree
Subject: Re: numerical string predicates
Date: 
Message-ID: <66bb7d31-6b71-47a2-b3bb-04c85a2dde4d@i12g2000prf.googlegroups.com>
Grrrrr.

If I run it, I get T no matter what.

(parseable-integer-p "1")

returns T, which is right.  However,

(parseable-integer-p "A")

returns T, which is wrong.  Empty strings, strings with no numbers,
strings of ALL numbers, long strings, short strings, and NIL all give
back T.

I can't imagine it would make a difference in this case, but I'm
running on Windows, and using SLIME.

Lee Crabtree

On Dec 13, 1:01 pm, Rainer Joswig <······@lisp.de> wrote:
> In article
> <····································@b1g2000pra.googlegroups.com>,
>
>
>
>  "lee.crabtree" <············@gmail.com> wrote:
> > Is there a way to tell if a string as a whole can be parsed as a
> > number?  In the specific case I'm working on, I only need to make sure
> > a string can be parsed as an integer, but I have no doubt that there's
> > a general purpose solution.
>
> > I know about PARSE-INTEGER, but the main problem is that it just bombs
> > out if there's a problem, and it returns success as soon as it finds
> > an integer value.  That is,
>
> > (parse-integer "1A")
>
> > returns successfully, and instead of NIL,
>
> > (parse-integer "A1")
>
> > signals a SIMPLE-PARSE-ERROR.
>
> > My attempt at figuring this out returned T no matter what was passed
> > to it, even NIL.  Here's where I got:
>
> > (defun parseable-integer-p (string-num)
> >   (handler-case
> >    (progn
> >      (parse-integer string-num :junk-allowed nil)
> >      t)
> >    (system::simple-parse-error (c)
> >            (declare (ignore c))
> >            nil)))
>
> > No matter what I pass into that, T is returned.  I'm using CLISP
> > version 2.43.
>
> > Any ideas?
>
> > Lee Crabtree
>
> Works for me in CLISP 2.41 on an Intel Mac.
>
> --http://lispm.dyndns.org/
From: Rainer Joswig
Subject: Re: numerical string predicates
Date: 
Message-ID: <joswig-12D5A4.20531313122007@news-europe.giganews.com>
In article 
<····································@i12g2000prf.googlegroups.com>,
 "lee.crabtree" <············@gmail.com> wrote:

> Grrrrr.
> 
> If I run it, I get T no matter what.
> 
> (parseable-integer-p "1")
> 
> returns T, which is right.  However,
> 
> (parseable-integer-p "A")
> 
> returns T, which is wrong.  Empty strings, strings with no numbers,
> strings of ALL numbers, long strings, short strings, and NIL all give
> back T.
> 
> I can't imagine it would make a difference in this case, but I'm
> running on Windows, and using SLIME.
> 
> Lee Crabtree


RJMBP:~ joswig$ clisp
  i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
  I I I I I I I      8     8   8           8     8     o  8    8
  I  \ `+' /  I      8         8           8     8        8    8
   \  `-+-'  /       8         8           8      ooooo   8oooo
    `-__|__-'        8         8           8           8  8
        |            8     o   8           8     o     8  8
  ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8

Welcome to GNU CLISP 2.41 (2006-10-13) <http://clisp.cons.org/>

Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2006

Type :h and hit Enter for context help.

[1]> (defun parseable-integer-p (string-num)
  (handler-case
   (progn
     (parse-integer string-num :junk-allowed nil)
     t)
   (system::simple-parse-error (c)
      (declare (ignore c))
      nil)))
PARSEABLE-INTEGER-P
[2]> (PARSEABLE-INTEGER-P "10")
T
[3]> (PARSEABLE-INTEGER-P "1A")
NIL
[4]> (parseable-integer-p "A")
NIL
[5]> 


> 
> On Dec 13, 1:01 pm, Rainer Joswig <······@lisp.de> wrote:
> > In article
> > <····································@b1g2000pra.googlegroups.com>,
> >
> >
> >
> >  "lee.crabtree" <············@gmail.com> wrote:
> > > Is there a way to tell if a string as a whole can be parsed as a
> > > number?  In the specific case I'm working on, I only need to make sure
> > > a string can be parsed as an integer, but I have no doubt that there's
> > > a general purpose solution.
> >
> > > I know about PARSE-INTEGER, but the main problem is that it just bombs
> > > out if there's a problem, and it returns success as soon as it finds
> > > an integer value.  That is,
> >
> > > (parse-integer "1A")
> >
> > > returns successfully, and instead of NIL,
> >
> > > (parse-integer "A1")
> >
> > > signals a SIMPLE-PARSE-ERROR.
> >
> > > My attempt at figuring this out returned T no matter what was passed
> > > to it, even NIL.  Here's where I got:
> >
> > > (defun parseable-integer-p (string-num)
> > >   (handler-case
> > >    (progn
> > >      (parse-integer string-num :junk-allowed nil)
> > >      t)
> > >    (system::simple-parse-error (c)
> > >            (declare (ignore c))
> > >            nil)))
> >
> > > No matter what I pass into that, T is returned.  I'm using CLISP
> > > version 2.43.
> >
> > > Any ideas?
> >
> > > Lee Crabtree
> >
> > Works for me in CLISP 2.41 on an Intel Mac.
> >
> > --http://lispm.dyndns.org/

-- 
http://lispm.dyndns.org/
From: Rainer Joswig
Subject: Re: numerical string predicates
Date: 
Message-ID: <joswig-FFA8FE.20595413122007@news-europe.giganews.com>
In article <····························@news-europe.giganews.com>,
 Rainer Joswig <······@lisp.de> wrote:

> In article 
> <····································@i12g2000prf.googlegroups.com>,
>  "lee.crabtree" <············@gmail.com> wrote:
> 
> > Grrrrr.
> > 
> > If I run it, I get T no matter what.
> > 
> > (parseable-integer-p "1")
> > 
> > returns T, which is right.  However,
> > 
> > (parseable-integer-p "A")
> > 
> > returns T, which is wrong.  Empty strings, strings with no numbers,
> > strings of ALL numbers, long strings, short strings, and NIL all give
> > back T.
> > 
> > I can't imagine it would make a difference in this case, but I'm
> > running on Windows, and using SLIME.

Can you run it without SLIME? What would be the result then?

> > 
> > Lee Crabtree
> 
> 
> RJMBP:~ joswig$ clisp
>   i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
>   I I I I I I I      8     8   8           8     8     o  8    8
>   I  \ `+' /  I      8         8           8     8        8    8
>    \  `-+-'  /       8         8           8      ooooo   8oooo
>     `-__|__-'        8         8           8           8  8
>         |            8     o   8           8     o     8  8
>   ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8
> 
> Welcome to GNU CLISP 2.41 (2006-10-13) <http://clisp.cons.org/>
> 
> Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
> Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
> Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
> Copyright (c) Bruno Haible, Sam Steingold 1999-2000
> Copyright (c) Sam Steingold, Bruno Haible 2001-2006
> 
> Type :h and hit Enter for context help.
> 
> [1]> (defun parseable-integer-p (string-num)
>   (handler-case
>    (progn
>      (parse-integer string-num :junk-allowed nil)
>      t)
>    (system::simple-parse-error (c)
>       (declare (ignore c))
>       nil)))
> PARSEABLE-INTEGER-P
> [2]> (PARSEABLE-INTEGER-P "10")
> T
> [3]> (PARSEABLE-INTEGER-P "1A")
> NIL
> [4]> (parseable-integer-p "A")
> NIL
> [5]> 
> 
> 
> > 
> > On Dec 13, 1:01 pm, Rainer Joswig <······@lisp.de> wrote:
> > > In article
> > > <····································@b1g2000pra.googlegroups.com>,
> > >
> > >
> > >
> > >  "lee.crabtree" <············@gmail.com> wrote:
> > > > Is there a way to tell if a string as a whole can be parsed as a
> > > > number?  In the specific case I'm working on, I only need to make sure
> > > > a string can be parsed as an integer, but I have no doubt that there's
> > > > a general purpose solution.
> > >
> > > > I know about PARSE-INTEGER, but the main problem is that it just bombs
> > > > out if there's a problem, and it returns success as soon as it finds
> > > > an integer value.  That is,
> > >
> > > > (parse-integer "1A")
> > >
> > > > returns successfully, and instead of NIL,
> > >
> > > > (parse-integer "A1")
> > >
> > > > signals a SIMPLE-PARSE-ERROR.
> > >
> > > > My attempt at figuring this out returned T no matter what was passed
> > > > to it, even NIL.  Here's where I got:
> > >
> > > > (defun parseable-integer-p (string-num)
> > > >   (handler-case
> > > >    (progn
> > > >      (parse-integer string-num :junk-allowed nil)
> > > >      t)
> > > >    (system::simple-parse-error (c)
> > > >            (declare (ignore c))
> > > >            nil)))
> > >
> > > > No matter what I pass into that, T is returned.  I'm using CLISP
> > > > version 2.43.
> > >
> > > > Any ideas?
> > >
> > > > Lee Crabtree
> > >
> > > Works for me in CLISP 2.41 on an Intel Mac.
> > >
> > > --http://lispm.dyndns.org/

-- 
http://lispm.dyndns.org/
From: lee.crabtree
Subject: Re: numerical string predicates
Date: 
Message-ID: <87d87ca7-1180-4c47-b2ab-b811237b76bf@i29g2000prf.googlegroups.com>
Looks like it's something to do with either Emacs or SLIME.  Running
CLISP straight from cmd.exe gave the expected results.  What would
keep that from working?

Lee Crabtree

On Dec 13, 1:59 pm, Rainer Joswig <······@lisp.de> wrote:
> In article <····························@news-europe.giganews.com>,
>  Rainer Joswig <······@lisp.de> wrote:
>
>
>
> > In article
> > <····································@i12g2000prf.googlegroups.com>,
> >  "lee.crabtree" <············@gmail.com> wrote:
>
> > > Grrrrr.
>
> > > If I run it, I get T no matter what.
>
> > > (parseable-integer-p "1")
>
> > > returns T, which is right.  However,
>
> > > (parseable-integer-p "A")
>
> > > returns T, which is wrong.  Empty strings, strings with no numbers,
> > > strings of ALL numbers, long strings, short strings, and NIL all give
> > > back T.
>
> > > I can't imagine it would make a difference in this case, but I'm
> > > running on Windows, and using SLIME.
>
> Can you run it without SLIME? What would be the result then?
>
>
>
>
>
> > > Lee Crabtree
>
> > RJMBP:~ joswig$ clisp
> >   i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
> >   I I I I I I I      8     8   8           8     8     o  8    8
> >   I  \ `+' /  I      8         8           8     8        8    8
> >    \  `-+-'  /       8         8           8      ooooo   8oooo
> >     `-__|__-'        8         8           8           8  8
> >         |            8     o   8           8     o     8  8
> >   ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8
>
> > Welcome to GNU CLISP 2.41 (2006-10-13) <http://clisp.cons.org/>
>
> > Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
> > Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
> > Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
> > Copyright (c) Bruno Haible, Sam Steingold 1999-2000
> > Copyright (c) Sam Steingold, Bruno Haible 2001-2006
>
> > Type :h and hit Enter for context help.
>
> > [1]> (defun parseable-integer-p (string-num)
> >   (handler-case
> >    (progn
> >      (parse-integer string-num :junk-allowed nil)
> >      t)
> >    (system::simple-parse-error (c)
> >       (declare (ignore c))
> >       nil)))
> > PARSEABLE-INTEGER-P
> > [2]> (PARSEABLE-INTEGER-P "10")
> > T
> > [3]> (PARSEABLE-INTEGER-P "1A")
> > NIL
> > [4]> (parseable-integer-p "A")
> > NIL
> > [5]>
>
> > > On Dec 13, 1:01 pm, Rainer Joswig <······@lisp.de> wrote:
> > > > In article
> > > > <····································@b1g2000pra.googlegroups.com>,
>
> > > >  "lee.crabtree" <············@gmail.com> wrote:
> > > > > Is there a way to tell if a string as a whole can be parsed as a
> > > > > number?  In the specific case I'm working on, I only need to make sure
> > > > > a string can be parsed as an integer, but I have no doubt that there's
> > > > > a general purpose solution.
>
> > > > > I know about PARSE-INTEGER, but the main problem is that it just bombs
> > > > > out if there's a problem, and it returns success as soon as it finds
> > > > > an integer value.  That is,
>
> > > > > (parse-integer "1A")
>
> > > > > returns successfully, and instead of NIL,
>
> > > > > (parse-integer "A1")
>
> > > > > signals a SIMPLE-PARSE-ERROR.
>
> > > > > My attempt at figuring this out returned T no matter what was passed
> > > > > to it, even NIL.  Here's where I got:
>
> > > > > (defun parseable-integer-p (string-num)
> > > > >   (handler-case
> > > > >    (progn
> > > > >      (parse-integer string-num :junk-allowed nil)
> > > > >      t)
> > > > >    (system::simple-parse-error (c)
> > > > >            (declare (ignore c))
> > > > >            nil)))
>
> > > > > No matter what I pass into that, T is returned.  I'm using CLISP
> > > > > version 2.43.
>
> > > > > Any ideas?
>
> > > > > Lee Crabtree
>
> > > > Works for me in CLISP 2.41 on an Intel Mac.
>
> > > > --http://lispm.dyndns.org/
>
> --http://lispm.dyndns.org/
From: Rainer Joswig
Subject: Re: numerical string predicates
Date: 
Message-ID: <joswig-105136.21564113122007@news-europe.giganews.com>
In article 
<····································@i29g2000prf.googlegroups.com>,
 "lee.crabtree" <············@gmail.com> wrote:

> Looks like it's something to do with either Emacs or SLIME.  Running
> CLISP straight from cmd.exe gave the expected results.  What would
> keep that from working?

I don't know. You might want to ask on the SLIME mailing list.

> 
> Lee Crabtree
> 
> On Dec 13, 1:59 pm, Rainer Joswig <······@lisp.de> wrote:
> > In article <····························@news-europe.giganews.com>,
> >  Rainer Joswig <······@lisp.de> wrote:
> >
> >
> >
> > > In article
> > > <····································@i12g2000prf.googlegroups.com>,
> > >  "lee.crabtree" <············@gmail.com> wrote:
> >
> > > > Grrrrr.
> >
> > > > If I run it, I get T no matter what.
> >
> > > > (parseable-integer-p "1")
> >
> > > > returns T, which is right.  However,
> >
> > > > (parseable-integer-p "A")
> >
> > > > returns T, which is wrong.  Empty strings, strings with no numbers,
> > > > strings of ALL numbers, long strings, short strings, and NIL all give
> > > > back T.
> >
> > > > I can't imagine it would make a difference in this case, but I'm
> > > > running on Windows, and using SLIME.
> >
> > Can you run it without SLIME? What would be the result then?
> >
> >
> >
> >
> >
> > > > Lee Crabtree
> >
> > > RJMBP:~ joswig$ clisp
> > >   i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
> > >   I I I I I I I      8     8   8           8     8     o  8    8
> > >   I  \ `+' /  I      8         8           8     8        8    8
> > >    \  `-+-'  /       8         8           8      ooooo   8oooo
> > >     `-__|__-'        8         8           8           8  8
> > >         |            8     o   8           8     o     8  8
> > >   ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8
> >
> > > Welcome to GNU CLISP 2.41 (2006-10-13) <http://clisp.cons.org/>
> >
> > > Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
> > > Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
> > > Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
> > > Copyright (c) Bruno Haible, Sam Steingold 1999-2000
> > > Copyright (c) Sam Steingold, Bruno Haible 2001-2006
> >
> > > Type :h and hit Enter for context help.
> >
> > > [1]> (defun parseable-integer-p (string-num)
> > >   (handler-case
> > >    (progn
> > >      (parse-integer string-num :junk-allowed nil)
> > >      t)
> > >    (system::simple-parse-error (c)
> > >       (declare (ignore c))
> > >       nil)))
> > > PARSEABLE-INTEGER-P
> > > [2]> (PARSEABLE-INTEGER-P "10")
> > > T
> > > [3]> (PARSEABLE-INTEGER-P "1A")
> > > NIL
> > > [4]> (parseable-integer-p "A")
> > > NIL
> > > [5]>
> >
> > > > On Dec 13, 1:01 pm, Rainer Joswig <······@lisp.de> wrote:
> > > > > In article
> > > > > <····································@b1g2000pra.googlegroups.com>,
> >
> > > > >  "lee.crabtree" <············@gmail.com> wrote:
> > > > > > Is there a way to tell if a string as a whole can be parsed as a
> > > > > > number?  In the specific case I'm working on, I only need to make sure
> > > > > > a string can be parsed as an integer, but I have no doubt that there's
> > > > > > a general purpose solution.
> >
> > > > > > I know about PARSE-INTEGER, but the main problem is that it just bombs
> > > > > > out if there's a problem, and it returns success as soon as it finds
> > > > > > an integer value.  That is,
> >
> > > > > > (parse-integer "1A")
> >
> > > > > > returns successfully, and instead of NIL,
> >
> > > > > > (parse-integer "A1")
> >
> > > > > > signals a SIMPLE-PARSE-ERROR.
> >
> > > > > > My attempt at figuring this out returned T no matter what was passed
> > > > > > to it, even NIL.  Here's where I got:
> >
> > > > > > (defun parseable-integer-p (string-num)
> > > > > >   (handler-case
> > > > > >    (progn
> > > > > >      (parse-integer string-num :junk-allowed nil)
> > > > > >      t)
> > > > > >    (system::simple-parse-error (c)
> > > > > >            (declare (ignore c))
> > > > > >            nil)))
> >
> > > > > > No matter what I pass into that, T is returned.  I'm using CLISP
> > > > > > version 2.43.
> >
> > > > > > Any ideas?
> >
> > > > > > Lee Crabtree
> >
> > > > > Works for me in CLISP 2.41 on an Intel Mac.
> >
> > > > > --http://lispm.dyndns.org/
> >
> > --http://lispm.dyndns.org/

-- 
http://lispm.dyndns.org/
From: lee.crabtree
Subject: Re: numerical string predicates
Date: 
Message-ID: <995c5def-6ecd-455b-81a0-57de7c0c0294@s19g2000prg.googlegroups.com>
Curiouser and curiouser...

If I enter the function directly into the SLIME REPL, it works like it
should.  However, if it's in a file, use C-c C-k to compile and load
it, and then run it, it acts screwy again.  It's only defined once in
the file.  What the hell?

Lee Crabtree

On Dec 13, 2:56 pm, Rainer Joswig <······@lisp.de> wrote:
> In article
> <····································@i29g2000prf.googlegroups.com>,
>
>  "lee.crabtree" <············@gmail.com> wrote:
> > Looks like it's something to do with either Emacs or SLIME.  Running
> > CLISP straight from cmd.exe gave the expected results.  What would
> > keep that from working?
>
> I don't know. You might want to ask on the SLIME mailing list.
>
>
>
>
>
> > Lee Crabtree
>
> > On Dec 13, 1:59 pm, Rainer Joswig <······@lisp.de> wrote:
> > > In article <····························@news-europe.giganews.com>,
> > >  Rainer Joswig <······@lisp.de> wrote:
>
> > > > In article
> > > > <····································@i12g2000prf.googlegroups.com>,
> > > >  "lee.crabtree" <············@gmail.com> wrote:
>
> > > > > Grrrrr.
>
> > > > > If I run it, I get T no matter what.
>
> > > > > (parseable-integer-p "1")
>
> > > > > returns T, which is right.  However,
>
> > > > > (parseable-integer-p "A")
>
> > > > > returns T, which is wrong.  Empty strings, strings with no numbers,
> > > > > strings of ALL numbers, long strings, short strings, and NIL all give
> > > > > back T.
>
> > > > > I can't imagine it would make a difference in this case, but I'm
> > > > > running on Windows, and using SLIME.
>
> > > Can you run it without SLIME? What would be the result then?
>
> > > > > Lee Crabtree
>
> > > > RJMBP:~ joswig$ clisp
> > > >   i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
> > > >   I I I I I I I      8     8   8           8     8     o  8    8
> > > >   I  \ `+' /  I      8         8           8     8        8    8
> > > >    \  `-+-'  /       8         8           8      ooooo   8oooo
> > > >     `-__|__-'        8         8           8           8  8
> > > >         |            8     o   8           8     o     8  8
> > > >   ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8
>
> > > > Welcome to GNU CLISP 2.41 (2006-10-13) <http://clisp.cons.org/>
>
> > > > Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
> > > > Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
> > > > Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
> > > > Copyright (c) Bruno Haible, Sam Steingold 1999-2000
> > > > Copyright (c) Sam Steingold, Bruno Haible 2001-2006
>
> > > > Type :h and hit Enter for context help.
>
> > > > [1]> (defun parseable-integer-p (string-num)
> > > >   (handler-case
> > > >    (progn
> > > >      (parse-integer string-num :junk-allowed nil)
> > > >      t)
> > > >    (system::simple-parse-error (c)
> > > >       (declare (ignore c))
> > > >       nil)))
> > > > PARSEABLE-INTEGER-P
> > > > [2]> (PARSEABLE-INTEGER-P "10")
> > > > T
> > > > [3]> (PARSEABLE-INTEGER-P "1A")
> > > > NIL
> > > > [4]> (parseable-integer-p "A")
> > > > NIL
> > > > [5]>
>
> > > > > On Dec 13, 1:01 pm, Rainer Joswig <······@lisp.de> wrote:
> > > > > > In article
> > > > > > <····································@b1g2000pra.googlegroups.com>,
>
> > > > > >  "lee.crabtree" <············@gmail.com> wrote:
> > > > > > > Is there a way to tell if a string as a whole can be parsed as a
> > > > > > > number?  In the specific case I'm working on, I only need to make sure
> > > > > > > a string can be parsed as an integer, but I have no doubt that there's
> > > > > > > a general purpose solution.
>
> > > > > > > I know about PARSE-INTEGER, but the main problem is that it just bombs
> > > > > > > out if there's a problem, and it returns success as soon as it finds
> > > > > > > an integer value.  That is,
>
> > > > > > > (parse-integer "1A")
>
> > > > > > > returns successfully, and instead of NIL,
>
> > > > > > > (parse-integer "A1")
>
> > > > > > > signals a SIMPLE-PARSE-ERROR.
>
> > > > > > > My attempt at figuring this out returned T no matter what was passed
> > > > > > > to it, even NIL.  Here's where I got:
>
> > > > > > > (defun parseable-integer-p (string-num)
> > > > > > >   (handler-case
> > > > > > >    (progn
> > > > > > >      (parse-integer string-num :junk-allowed nil)
> > > > > > >      t)
> > > > > > >    (system::simple-parse-error (c)
> > > > > > >            (declare (ignore c))
> > > > > > >            nil)))
>
> > > > > > > No matter what I pass into that, T is returned.  I'm using CLISP
> > > > > > > version 2.43.
>
> > > > > > > Any ideas?
>
> > > > > > > Lee Crabtree
>
> > > > > > Works for me in CLISP 2.41 on an Intel Mac.
>
> > > > > > --http://lispm.dyndns.org/
>
> > > --http://lispm.dyndns.org/
>
> --http://lispm.dyndns.org/
From: Geoffrey Summerhayes
Subject: Re: numerical string predicates
Date: 
Message-ID: <f8a7bf53-ea03-4e67-8cde-5b8ec1723538@e6g2000prf.googlegroups.com>
On Dec 13, 4:12 pm, "lee.crabtree" <············@gmail.com> wrote:
> Curiouser and curiouser...
>
> If I enter the function directly into the SLIME REPL, it works like it
> should.  However, if it's in a file, use C-c C-k to compile and load
> it, and then run it, it acts screwy again.  It's only defined once in
> the file.  What the hell?

Who's good at reading clisp opcodes?

I've replicated the problem, the compiled code
behaves as if the parse-integer call is being
optimized out as having no side effects, BUT...
it's listed in the disassembly and looks like
it's being called.

Removing the PROGN..T surrounding PARSE-INTEGER
and it behaves correctly returning a number or nil.

Here's the disassembly of the original:

Disassembly of function PARSEABLE-INTEGER-P
(CONST 0) = #(NIL)
(CONST 1) = #<COMPILED-FUNCTION PARSEABLE-INTEGER-P-1>
(CONST 2) = #<COMPILED-FUNCTION PARSEABLE-INTEGER-P-2>
(CONST 3) = (#(SYSTEM::SIMPLE-PARSE-ERROR 25) 1 . 1)
1 required argument
0 optional arguments
No rest parameter
No keyword parameters
27 byte-code instructions:
0     (NIL)
1     (MAKE-VECTOR1&PUSH 1)
3     (NIL)
4     (STOREC 0 0)
7     (TAGBODY-OPEN 0 L40)                ; #(NIL)
10    (LOAD&PUSH 4)
11    (LOAD&PUSH 3)
12    (COPY-CLOSURE&PUSH 1 2)             ; #
15    (CONST&PUSH 2)                      ; #
16    (HANDLER-OPEN 3 L25)                ; (# 1 . 1)
18    (LOAD&PUSH 4)
19    (FUNCALL 0)
21    (SKIP 6)
23    (JMP L41)
25    L25
25    (HANDLER-BEGIN&PUSH)
26    (LOADI&PUSH 0 0 1)
30    (FUNCALL&PUSH 0)
32    (LOAD&PUSH 1)
33    (FUNCALL 1)
35    (SKIPSP 2 1)
38    (SKIP&RET 2)
40    L40
40    (NIL)
41    L41
41    (TAGBODY-CLOSE)
42    (SKIP&RET 3)

and the modified version:

Disassembly of function PARSEABLE-INTEGER-P
(CONST 0) = #(NIL)
(CONST 1) = #<COMPILED-FUNCTION PARSEABLE-INTEGER-P-1>
(CONST 2) = #<COMPILED-FUNCTION PARSEABLE-INTEGER-P-2>
(CONST 3) = (#(SYSTEM::SIMPLE-PARSE-ERROR 35) 1 . 1)
1 required argument
0 optional arguments
No rest parameter
No keyword parameters
31 byte-code instructions:
0     (NIL)
1     (MAKE-VECTOR1&PUSH 1)
3     (LOAD&STOREC 2 0 0)
7     (LOAD 0)
8     (MAKE-VECTOR1&PUSH 1)
10    (NIL)
11    (STOREC 0 0)
14    (TAGBODY-OPEN 0 L50)                ; #(NIL)
17    (LOAD&PUSH 4)
18    (LOAD&PUSH 3)
19    (COPY-CLOSURE&PUSH 1 2)             ; #
22    (LOAD&PUSH 5)
23    (COPY-CLOSURE&PUSH 2 1)             ; #
26    (HANDLER-OPEN 3 L35)                ; (# 1 . 1)
28    (LOAD&PUSH 4)
29    (FUNCALL 0)
31    (SKIP 6)
33    (JMP L51)
35    L35
35    (HANDLER-BEGIN&PUSH)
36    (LOADI&PUSH 0 0 1)
40    (FUNCALL&PUSH 0)
42    (LOAD&PUSH 1)
43    (FUNCALL 1)
45    (SKIPSP 2 1)
48    (SKIP&RET 2)
50    L50
50    (NIL)
51    L51
51    (TAGBODY-CLOSE)
52    (SKIP&RET 4)

Maybe tomorrow I'll have time to work through
it, but I thought I'd post this and see if
anyone is used to reading this.

----
Geoff
From: lee.crabtree
Subject: Re: numerical string predicates
Date: 
Message-ID: <a9bb7fdc-3bd4-4454-9f04-c43e0f83c4ae@s12g2000prg.googlegroups.com>
I came to the same conclusion via a different path.

I don't know enough about CLISP to know what kind of optimizations it
can perform, but I realized that since PARSE-INTEGER doesn't have a
side effect and isn't the returning expression, it could be considered
safe to optimize away.  As a quick test, I added this:

(when (parse-integer string-num :junk-allowed nil)
   ...

And it worked.

On Dec 14, 10:47 am, Geoffrey Summerhayes <·······@gmail.com> wrote:
> On Dec 13, 4:12 pm, "lee.crabtree" <············@gmail.com> wrote:
>
> > Curiouser and curiouser...
>
> > If I enter the function directly into the SLIME REPL, it works like it
> > should.  However, if it's in a file, use C-c C-k to compile and load
> > it, and then run it, it acts screwy again.  It's only defined once in
> > the file.  What the hell?
>
> Who's good at reading clisp opcodes?
>
> I've replicated the problem, the compiled code
> behaves as if the parse-integer call is being
> optimized out as having no side effects, BUT...
> it's listed in the disassembly and looks like
> it's being called.
>
> Removing the PROGN..T surrounding PARSE-INTEGER
> and it behaves correctly returning a number or nil.
>
> Here's the disassembly of the original:
>
> Disassembly of function PARSEABLE-INTEGER-P
> (CONST 0) = #(NIL)
> (CONST 1) = #<COMPILED-FUNCTION PARSEABLE-INTEGER-P-1>
> (CONST 2) = #<COMPILED-FUNCTION PARSEABLE-INTEGER-P-2>
> (CONST 3) = (#(SYSTEM::SIMPLE-PARSE-ERROR 25) 1 . 1)
> 1 required argument
> 0 optional arguments
> No rest parameter
> No keyword parameters
> 27 byte-code instructions:
> 0     (NIL)
> 1     (MAKE-VECTOR1&PUSH 1)
> 3     (NIL)
> 4     (STOREC 0 0)
> 7     (TAGBODY-OPEN 0 L40)                ; #(NIL)
> 10    (LOAD&PUSH 4)
> 11    (LOAD&PUSH 3)
> 12    (COPY-CLOSURE&PUSH 1 2)             ; #
> 15    (CONST&PUSH 2)                      ; #
> 16    (HANDLER-OPEN 3 L25)                ; (# 1 . 1)
> 18    (LOAD&PUSH 4)
> 19    (FUNCALL 0)
> 21    (SKIP 6)
> 23    (JMP L41)
> 25    L25
> 25    (HANDLER-BEGIN&PUSH)
> 26    (LOADI&PUSH 0 0 1)
> 30    (FUNCALL&PUSH 0)
> 32    (LOAD&PUSH 1)
> 33    (FUNCALL 1)
> 35    (SKIPSP 2 1)
> 38    (SKIP&RET 2)
> 40    L40
> 40    (NIL)
> 41    L41
> 41    (TAGBODY-CLOSE)
> 42    (SKIP&RET 3)
>
> and the modified version:
>
> Disassembly of function PARSEABLE-INTEGER-P
> (CONST 0) = #(NIL)
> (CONST 1) = #<COMPILED-FUNCTION PARSEABLE-INTEGER-P-1>
> (CONST 2) = #<COMPILED-FUNCTION PARSEABLE-INTEGER-P-2>
> (CONST 3) = (#(SYSTEM::SIMPLE-PARSE-ERROR 35) 1 . 1)
> 1 required argument
> 0 optional arguments
> No rest parameter
> No keyword parameters
> 31 byte-code instructions:
> 0     (NIL)
> 1     (MAKE-VECTOR1&PUSH 1)
> 3     (LOAD&STOREC 2 0 0)
> 7     (LOAD 0)
> 8     (MAKE-VECTOR1&PUSH 1)
> 10    (NIL)
> 11    (STOREC 0 0)
> 14    (TAGBODY-OPEN 0 L50)                ; #(NIL)
> 17    (LOAD&PUSH 4)
> 18    (LOAD&PUSH 3)
> 19    (COPY-CLOSURE&PUSH 1 2)             ; #
> 22    (LOAD&PUSH 5)
> 23    (COPY-CLOSURE&PUSH 2 1)             ; #
> 26    (HANDLER-OPEN 3 L35)                ; (# 1 . 1)
> 28    (LOAD&PUSH 4)
> 29    (FUNCALL 0)
> 31    (SKIP 6)
> 33    (JMP L51)
> 35    L35
> 35    (HANDLER-BEGIN&PUSH)
> 36    (LOADI&PUSH 0 0 1)
> 40    (FUNCALL&PUSH 0)
> 42    (LOAD&PUSH 1)
> 43    (FUNCALL 1)
> 45    (SKIPSP 2 1)
> 48    (SKIP&RET 2)
> 50    L50
> 50    (NIL)
> 51    L51
> 51    (TAGBODY-CLOSE)
> 52    (SKIP&RET 4)
>
> Maybe tomorrow I'll have time to work through
> it, but I thought I'd post this and see if
> anyone is used to reading this.
>
> ----
> Geoff
From: Stanisław Halik
Subject: Re: numerical string predicates
Date: 
Message-ID: <fk0c5n$auk$1@news2.task.gda.pl>
thus spoke lee.crabtree <············@gmail.com>:

> I don't know enough about CLISP to know what kind of optimizations it
> can perform, but I realized that since PARSE-INTEGER doesn't have a
> side effect and isn't the returning expression, it could be considered
> safe to optimize away.  As a quick test, I added this:

> (when (parse-integer string-num :junk-allowed nil)
>   ...

> And it worked.

Looks like a grave bug in the optimizer.

-- 
mirrors are more fun than television
From: Richard M Kreuter
Subject: Re: numerical string predicates
Date: 
Message-ID: <87aboew6do.fsf@progn.net>
"lee.crabtree" <············@gmail.com> writes:

> Is there a way to tell if a string as a whole can be parsed as a
> number? ... I know about PARSE-INTEGER, but the main problem is that
> it just bombs out if there's a problem, and it returns success as
> soon as it finds an integer value.  That is,
>
> (parse-integer "1A")
>
> returns successfully, and instead of NIL,

PARSE-INTEGER returns two values: the integer parsed (or NIL), and the
index of the first invalid character seen.

(parse-integer "1A" :junk-allowed t)
=> 1
=> 1

So by comparing the second value to the length of the string, you can
tell whether the parse reached the end of the string (or an END
argument, if you use one):

(defun parse-integer-or-bust (string &key (radix 10) (start 0) end)
  (multiple-value-bind (integer stop)
      (parse-integer string :start start :end end
		     :junk-allowed t :radix radix)
    (and (= stop (or end (length string))) integer)))
=> PARSE-INTEGER-OR-BUST
(parse-integer-or-bust "x12y")
=> NIL
(parse-integer-or-bust "x12y" :start 1)
=> NIL
(parse-integer-or-bust "x12y" :start 1 :end 2)
=> 1
(parse-integer-or-bust "x12y" :start 1 :end 3)
=> 12
From: Steven M. Haflich
Subject: Re: numerical string predicates
Date: 
Message-ID: <Dij9j.80477$Um6.19828@newssvr12.news.prodigy.net>
lee.crabtree wrote:

> Is there a way to tell if a string as a whole can be parsed as a
> number?  In the specific case I'm working on, I only need to make sure
> a string can be parsed as an integer, but I have no doubt that there's
> a general purpose solution.

A number of solutions have been proposed using parse-integer itself to 
answer the question.  But the stated question was not to parse the 
string as an integer, but only whether the given string could be parsed 
as an integer without error.

If you have a regular expression package available in your 
implementation you could test with this predicate:

  (regexp:match-re "^\\s*[+-]?[0-9]+\\s*$" string)

This works in Allegro, but but should work the same using cl-ppcre in 
any other ANSI CL.