From: Ira H. Fuchs
Subject: manipulating integers as strings
Date: 
Message-ID: <3ng8j5$efb@cnn.Princeton.EDU>
Can someone tell me how I can take an integer, reverse its digits, and then use
it as an argument to a function which requires a numeric argument? The function
which does the reversal should be efficient as it will have to work with
arbitrarily large integers. I tried converting the integer using the pack
function (explode) and was then able to use reverse but getting the result back
to an integer has so far eluded me.

From: David Schulenburg
Subject: Re: manipulating integers as strings
Date: 
Message-ID: <3np0mo$3p0@news.aero.org>
In article <··········@cnn.Princeton.EDU>, "Ira H. Fuchs" <·····@princeton.edu> writes:
|> Can someone tell me how I can take an integer, reverse its digits, and then use
|> it as an argument to a function which requires a numeric argument? The function
|> which does the reversal should be efficient as it will have to work with
|> arbitrarily large integers. I tried converting the integer using the pack
|> function (explode) and was then able to use reverse but getting the result back
|> to an integer has so far eluded me.
|> 

there might be better ways to do this; but, the following will work.

[1c] USER(38): (setq n 12345)
12345
[1c] USER(39): (format nil "~a" n)
"12345"
[1c] USER(40): (nreverse *)
"54321"
[1c] USER(41): (read-from-string *)
54321
5
[1c] USER(42): 
From: Thomas A. Russ
Subject: Re: manipulating integers as strings
Date: 
Message-ID: <TAR.95Apr27142827@hobbes.ISI.EDU>
  (read-from-string (nreverse (princ-to-string <number>)))

--
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Luigi Semenzato
Subject: Re: manipulating integers as strings
Date: 
Message-ID: <3npiep$ehb@fido.asd.sgi.com>
In article <··········@cnn.Princeton.EDU>, "Ira H. Fuchs" <·····@princeton.edu> 
writes:

|> Can someone tell me how I can take an integer, reverse its digits, and then use
|> it as an argument to a function which requires a numeric argument? The function
|> which does the reversal should be efficient as it will have to work with
|> arbitrarily large integers. I tried converting the integer using the pack
|> function (explode) and was then able to use reverse but getting the result back
|> to an integer has so far eluded me.

In Common Lisp:

(with-input-from-string (port (reverse (format nil "~d" n))) (read port))

---Luigi