From: ···@franz.com
Subject: Re: manipulating integers as strings
Date: 
Message-ID: <1995Apr28.024512.6779@franz.com>
> >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

> Ira, how about using a function like the one below, which reverses
> the digits without creating any intermediate strings? (It does build
> a list though!).

This version doesn't allocate any storage:

(defun reverse-number (n)
  (do ((rev 0)) 
      (())
    (multiple-value-bind (q r) (truncate n 10)
      (setf rev (+ (* rev 10) r))
      (if (zerop (setf n q))
	  (return rev))))


-Kelly Murray   ···@franz.com   Franz, Inc.  Berkeley, CA
From: Bruno Haible
Subject: Re: manipulating integers as strings
Date: 
Message-ID: <3o5f18$1jtp@info4.rus.uni-stuttgart.de>
> This version doesn't allocate any storage:

And it also works for negative integers, unlike most of the other solutions
that were posted.


                    Bruno Haible