From: Johan Kullstam
Subject: nested format
Date: 
Message-ID: <m365y24sc4.fsf@sysengr.res.ray.com>
Is there a better way to do this?

I want to set a variable number of bits for a display field.  This
works, but seems a bit clumsy.  Is there a better way which avoids
nesting formats?  I checked the hyperspec but didn't see anything
obvious.

In this case, I want to have a 30 bit word printed out in binary.

;;This has format create a format string.
[43]> (format nil "~~&~~~D,'0B~~%" 30)
"~&~30,'0B~%"

;;Now I use that format string created above.
[44]> (format t (format nil "~~&~~~D,'0B~~%" 30) 24)
000000000000000000000000011000
NIL

-- 
Johan KULLSTAM <··········@attbi.com> sysengr

From: Nils Goesche
Subject: Re: nested format
Date: 
Message-ID: <lkwuqik7y5.fsf@pc022.bln.elmeg.de>
Johan Kullstam <··········@attbi.com> writes:

> Is there a better way to do this?
> 
> I want to set a variable number of bits for a display field.  This
> works, but seems a bit clumsy.  Is there a better way which avoids
> nesting formats?  I checked the hyperspec but didn't see anything
> obvious.
> 
> In this case, I want to have a 30 bit word printed out in binary.
> 
> ;;This has format create a format string.
> [43]> (format nil "~~&~~~D,'0B~~%" 30)
> "~&~30,'0B~%"
> 
> ;;Now I use that format string created above.
> [44]> (format t (format nil "~~&~~~D,'0B~~%" 30) 24)
> 000000000000000000000000011000
> NIL

CL-USER 90 > (format t "~&~V,'0B~%" 30 24)
000000000000000000000000011000
NIL

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0
From: Thomas A. Russ
Subject: Re: nested format
Date: 
Message-ID: <ymi4rdlwdlp.fsf@sevak.isi.edu>
Nils Goesche <······@cartan.de> writes:

> 
> CL-USER 90 > (format t "~&~V,'0B~%" 30 24)
> 000000000000000000000000011000
> NIL
> 
> Regards,
> -- 
> Nils Goesche
> "Don't ask for whom the <CTRL-G> tolls."

In case this is a bit too cryptic, the key is to use "V" in
place of the parameter.

HyperSpec section 22.3:
  ...
  In place of a prefix parameter to a directive, V (or v) can be used. In
  this case, format takes an argument from args as a parameter to the
  directive. The argument should be an integer or character. If the arg
  used by a V parameter is nil, the effect is as if the parameter had been
  omitted....

  
-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu