> >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
> 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