From: rkk on
If I want to print a fixed width hex number, I can do the following:

(format t "~6,'0X" 1234)

to get 0004D2

How do I do this for base 36 numbers? (format t "~36R" 1234) gives YA;
I want 0000YA. I guess my question is how do I combine the ~6,'0 and
the ~36R directives.

Thanks,
Rajesh
From: Barry Margolin on
In article
<a2f90d7d-72f0-482a-95f0-e27f19df2d97(a)u34g2000yqu.googlegroups.com>,
rkk <rajesh.kommu(a)gmail.com> wrote:

> If I want to print a fixed width hex number, I can do the following:
>
> (format t "~6,'0X" 1234)
>
> to get 0004D2
>
> How do I do this for base 36 numbers? (format t "~36R" 1234) gives YA;
> I want 0000YA. I guess my question is how do I combine the ~6,'0 and
> the ~36R directives.

You do it the same way. ~R is like ~D and ~X, except there's an extra
first parameter specifying the radix. So you want ~36,6,'0R.

There's even an example of this in the Hyperspec section on ~R,
http://www.lispworks.com/documentation/HyperSpec/Body/22_cba.htm.

--
Barry Margolin, barmar(a)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: Rob Warnock on
rkk <rajesh.kommu(a)gmail.com> wrote:
+---------------
| If I want to print a fixed width hex number, I can do the following:
|
| (format t "~6,'0X" 1234)
|
| to get 0004D2
|
| How do I do this for base 36 numbers? (format t "~36R" 1234) gives YA;
| I want 0000YA. I guess my question is how do I combine the ~6,'0 and
| the ~36R directives.
+---------------

Uhhh... Do you have a local copy of the Common Lisp HyperSpec (CLHS)?
If not, *GET ONE ASAP*!!

http://www.lispworks.com/documentation/HyperSpec/Body/22_cba.htm
22.3.2.1 Tilde R: Radix

~nR prints arg in radix n. The modifier flags and any remaining
parameters are used as for the ~D directive. ~D is the same as ~10R.
The full form is ~radix,mincol,padchar,commachar,comma-intervalR.
...

The ~D directive is described here:

http://www.lispworks.com/documentation/HyperSpec/Body/22_cbb.htm
22.3.2.2 Tilde D: Decimal
...
Thus the most general form of ~D is ~mincol,padchar,commachar,
comma-intervalD.
...

Compare the last sentence quoted above from each section.


-Rob

-----
Rob Warnock <rpw3(a)rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607