I was reading CLtL2 and the hyperspec yesterday to try to find a
succinct way of printing a list of values, with a particular twist.
However, my eyes started to hurt before I found what I was looking
for. Perhaps someone else has this information cached in their head
and can retrieve it for me.
I want a format control string, FMTSTR, that will generate the
following:
(format nil FMTSTR '(1 2 nil 3 4)) ==> "1 2 . 3 4"
That is, substitute an `alternate' string in the case of a nil. This
is a wrinkle on a format control string I'd been using:
····@[~A~]~^ ~}"
which does the space delimiting for me. I tried various combinations
of tilde left-bracket conditional expressions, but they seemed to eat
two arguments. In the end, I punted by using:
(substitute-if-not "." #'(lambda (x) x) list-o-values)
to modify the list supplied to format.
Hints?
--
Russell Senior ``The two chiefs turned to each other.
·······@teleport.com Bellison uncorked a flood of horrible
profanity, which, translated meant, `This is
extremely unusual.' ''
Russell Senior wrote:
> I want a format control string, FMTSTR, that will generate the
> following:
>
> (format nil FMTSTR '(1 2 nil 3 4)) ==> "1 2 . 3 4"
>
> That is, substitute an `alternate' string in the case of a nil. This
> is a wrinkle on a format control string I'd been using:
>
> ····@[~A~]~^ ~}"
>
> which does the space delimiting for me. I tried various combinations
> of tilde left-bracket conditional expressions, but they seemed to eat
> two arguments. In the end, I punted by using:
~:* backs up one argument, so
(format nil "~{~:[.~;~:*~A~]~^ ~}" '(1 2 3 nil 4 5)) ==> "1 2 3 . 4 5"
--
Gareth McCaughan Dept. of Pure Mathematics & Math. Statistics,
················@pobox.com Cambridge University, England.
Russell Senior <·······@teleport.com> writes:
> I want a format control string, FMTSTR, that will generate the
> following:
>
> (format nil FMTSTR '(1 2 nil 3 4)) ==> "1 2 . 3 4"
>
> That is, substitute an `alternate' string in the case of a nil. This
> is a wrinkle on a format control string I'd been using:
>
> ····@[~A~]~^ ~}"
try "~{~:[.~;~:*~A~]~^ ~}"
> which does the space delimiting for me. I tried various combinations
> of tilde left-bracket conditional expressions, but they seemed to eat
> two arguments.
The key is to use the colon modified ~:* directive to backup over the
non-nil argument that was consumed by the ~:[ directive.
--
Thomas A. Russ, USC/Information Sciences Institute ···@isi.edu