From: John Gillespie
Subject: atoi in lisp?
Date: 
Message-ID: <CtxBGF.1Gv@ucdavis.edu>
I'm new at this lisp thing... How do you convert a string to a
number, like atoi or atof in C?  I use 

(defun aton (str)
  (when (> (length str) 0)
        (read (make-string-input-stream str))))

but there must be a function somewhere that does this.  (Steele's book
sure is big :-( ).

john
···········@ucdavis.edu

From: David Schulenburg
Subject: Re: atoi in lisp?
Date: 
Message-ID: <31met0$mtm@news.aero.org>
In article <··········@ucdavis.edu>, ····@josquin.ucdavis.edu (John Gillespie) writes:
|> I'm new at this lisp thing... How do you convert a string to a
              ^^^^^^^^^^^^^^^
that is truly funny!

|> number, like atoi or atof in C?  I use 
|> 
|> (defun aton (str)
|>   (when (> (length str) 0)
|>         (read (make-string-input-stream str))))
|> 
|> but there must be a function somewhere that does this.  (Steele's book
|> sure is big :-( ).                                       ^^^^^^^^^^^^^
   ^^^^^^^^^^^

so is this :-)

|> john
|> ···········@ucdavis.edu

try read-from-string.  this will read whatever object is contained in
its string argument.  unlike C, where you have a zillion :-( functions
to read objects from strings, lisp has only one such function!

david
From: Armadeus
Subject: Re: atoi in lisp?
Date: 
Message-ID: <1994Aug5.110809.31790@waikato.ac.nz>
In article <··········@ucdavis.edu>, ····@josquin.ucdavis.edu (John Gillespie) writes:
> I'm new at this lisp thing... How do you convert a string to a
> number, like atoi or atof in C?  I use 
> 
> (defun aton (str)
>   (when (> (length str) 0)
>         (read (make-string-input-stream str))))
> 
> but there must be a function somewhere that does this.  (Steele's book
> sure is big :-( ).
> 

(setq out (read-from-string <str>))

Also, check *read-default-float-format* - if you want true double float
precision (without using IEEE coersion) set this global var to be 'double-float
  



		           From Martin Glanvill

--===**| "Arm Powered" Dodo Breeder's Association of New Zealand Inc. |**===--	
e-mail     : ···@hoiho.math.waikato.ac.nz	            
								******** 
snail-mail : c/- Dept Mathematics & Statistics			*****/|*
             University of Waikato				****/#|*
             PO Box 3105					***/__|*
             Hamilton 2020					**/~~~|*
             New Zealand					********

A bird in the hand is safer than two overhead.
From: Barry Margolin
Subject: Re: atoi in lisp?
Date: 
Message-ID: <328m2vINN9mi@early-bird.think.com>
In article <··········@ucdavis.edu> ····@josquin.ucdavis.edu (John Gillespie) writes:
>I'm new at this lisp thing... How do you convert a string to a
>number, like atoi or atof in C?  I use 

The CL equivalent of atoi() is PARSE-INTEGER.  There is no direct analogue
of atof(), so you have to use READ-FROM-STRING and appropriate error
checking (including handling the condition that will be raised if EOF is
encountered in the middle of an object, due to mismatched parentheses).
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar