Hello.
I searched for a format directive which would allow me to print n identical
characters, but could not find anything. Is that possible?
e.g.
----------------------------------------------------------------
--> (format t "~64,-?~%")
Thanks, Nicolas.
* Nicolas Neuss wrote:
> Hello.
> I searched for a format directive which would allow me to print n identical
> characters, but could not find anything. Is that possible?
Something like this?
(format nil ···@{~C~:*~} 20 #\x)
The format control means:
··@{ Start iteration, using the next arg as the max count,
and using all the remaining args to FORMAT to iterate over
~C print a character (using up one arg)
~:* back up one arg
~} end iteration
--tim
Tim Bradshaw <···@cley.com> writes:
> * Nicolas Neuss wrote:
> > Hello.
> > I searched for a format directive which would allow me to print n identical
> > characters, but could not find anything. Is that possible?
>
> Something like this?
>
> (format nil ···@{~C~:*~} 20 #\x)
Another one, using padding:
(format nil "~V,,,V<~>" 20 #\=)
Nicolas Neuss <·············@iwr.uni-heidelberg.de> writes:
> I searched for a format directive which would allow me to print n identical
> characters, but could not find anything. Is that possible?
>
> e.g.
>
> ----------------------------------------------------------------
>
> --> (format t "~64,-?~%")
Cheating a little bit:
(format t "~,,64,'?A" '||)
Petter
--
________________________________________________________________________
Petter Gustad 8'h2B | ~8'h2B http://www.gustad.com/petter
Petter Gustad <·············@gustad.com> writes:
> Nicolas Neuss <·············@iwr.uni-heidelberg.de> writes:
>
> > I searched for a format directive which would allow me to print n identical
> > characters, but could not find anything. Is that possible?
> >
> > e.g.
> >
> > ----------------------------------------------------------------
> >
> > --> (format t "~64,-?~%")
>
> Cheating a little bit:
>
> (format t "~,,64,'?A" '||)
Or if you want dash rather than question-mark:
(format t "~,,64,'-A~%" '||)
Petter
--
________________________________________________________________________
Petter Gustad 8'h2B | ~8'h2B http://www.gustad.com/petter
Petter Gustad <·············@gustad.com> writes:
> (format t "~,,64,'-A~%" '||)
That's something I had also thought of (but not worked out). What I do not
like is the dummy argument it needs (same for Tim's solution).
Hmm, I would think such a thing to be a useful extension to format, but
maybe I'm wrong...
Nicolas.
Nicolas Neuss <·············@iwr.uni-heidelberg.de> writes:
> Petter Gustad <·············@gustad.com> writes:
>
> > (format t "~,,64,'-A~%" '||)
>
> That's something I had also thought of (but not worked out). What I
> do not like is the dummy argument it needs (same for Tim's
> solution).
Tim's solution was much more elegant than mine. Further, his does not
require a dummy argument? The arguments were the count and the
character to be printed.
(format nil ···@{~C~:*~}" 64 #\-)
Petter
--
________________________________________________________________________
Petter Gustad 8'h2B | ~8'h2B http://www.gustad.com/petter
Petter Gustad <·············@gustad.com> writes:
>
> Tim's solution was much more elegant than mine. Further, his does not
> require a dummy argument? The arguments were the count and the
> character to be printed.
>
> (format nil ···@{~C~:*~}" 64 #\-)
>
> Petter
Sorry, I formulated my reply too sloppy. His solution is more general than
necessary for me here and requires arguments which I would like to have
inside the format string. I guess Wolfhard's solution is what I searched
for.
Thanks to all of you.
Nicolas.
"Nicolas Neuss" <·············@iwr.uni-heidelberg.de> wrote in message
···················@ortler.iwr.uni-heidelberg.de...
> Petter Gustad <·············@gustad.com> writes:
>
> >
> > Tim's solution was much more elegant than mine. Further, his does not
> > require a dummy argument? The arguments were the count and the
> > character to be printed.
> >
> > (format nil ···@{~C~:*~}" 64 #\-)
> >
> > Petter
>
> Sorry, I formulated my reply too sloppy. His solution is more general
than
> necessary for me here and requires arguments which I would like to have
> inside the format string. I guess Wolfhard's solution is what I searched
> for.
Honestly, for something like this I would just use (make-string 64
:initial-element #\-) and print that. It is doubly better IMO if you are
just returning the string. Maybe I am still just format-directive shy, but
I like the exchange of brevity for readability.
--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
"Coby Beck" <·····@mercury.bc.ca> writes:
> Honestly, for something like this I would just use (make-string 64
> :initial-element #\-) and print that. It is doubly better IMO if you are
> just returning the string. Maybe I am still just format-directive shy,
> but I like the exchange of brevity for readability.
Maybe. But seeing
(format t "~64,,,'-<~>")
or
(format nil "~V,,,V<~>" 20 #\=)
in source code immediately leads to a better understanding of the format
section of the Hyperspec which is not a bad thing IMO:-) Of course, it is
not advisable to show something like that proudly to someone else.
Nicolas.
* Nicolas Neuss wrote:
> That's something I had also thought of (but not worked out). What I do not
> like is the dummy argument it needs (same for Tim's solution).
Mine doesn't have a dummy argument, it has one argument which is the
repeat count and one which is the character.
--tim
Petter Gustad <·············@gustad.com> writes:
>
> (format t "~,,64,'-A~%" '||)
Nicolas Neuss <·············@iwr.uni-heidelberg.de> writes:
>
> That's something I had also thought of (but not worked out). What I do not
> like is the dummy argument it needs (same for Tim's solution).
Two possible forms with lesser dummy arguments:
(format t ····@{~A~:*~}" #\-)
(format t "~64,,,'-<~>")
Hope this helps.
--
"I believe in the horse. The automobile is a passing phenomenon."
-- Kaiser Wilhelm II. (1859-1941)
Nicolas Neuss <·············@iwr.uni-heidelberg.de> writes:
>
> Hello.
>
> I searched for a format directive which would allow me to print n identical
> characters, but could not find anything. Is that possible?
The following would work:
(defun print-n-characters (n char)
(format nil "~v,,,vA" n char ""))
What it does is print the empty string in a field of width N, with
the padding character specified to be whatever you want. It uses the
"v" parameter form to read the format parameter from the argument list.
--
Thomas A. Russ, USC/Information Sciences Institute ···@isi.edu