From: Nicolas Neuss
Subject: format directive
Date: 
Message-ID: <87hecbhmnb.fsf@ortler.iwr.uni-heidelberg.de>
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.

From: Tim Bradshaw
Subject: Re: format directive
Date: 
Message-ID: <ey3vg0r93vw.fsf@cley.com>
* 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
From: Gerd Moellmann
Subject: Re: format directive
Date: 
Message-ID: <86y95mzewj.fsf@gerd.free-bsd.org>
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 #\=)
From: Petter Gustad
Subject: Re: format directive
Date: 
Message-ID: <m3vg0rq0zk.fsf@scimul.dolphinics.no>
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
From: Petter Gustad
Subject: Re: format directive
Date: 
Message-ID: <m3r8bfq0ss.fsf@scimul.dolphinics.no>
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
From: Nicolas Neuss
Subject: Re: format directive
Date: 
Message-ID: <87el7er2bj.fsf@ortler.iwr.uni-heidelberg.de>
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.
From: Petter Gustad
Subject: Re: format directive
Date: 
Message-ID: <m3n0m2pm3b.fsf@scimul.dolphinics.no>
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
From: Nicolas Neuss
Subject: Re: format directive
Date: 
Message-ID: <87adi2qygd.fsf@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.

Thanks to all of you.

Nicolas.
From: Coby Beck
Subject: Re: format directive
Date: 
Message-ID: <b04s7s$1osl$1@otis.netspace.net.au>
"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")
From: Nicolas Neuss
Subject: Re: format directive
Date: 
Message-ID: <87n0m1latd.fsf@ortler.iwr.uni-heidelberg.de>
"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.
From: Tim Bradshaw
Subject: Re: format directive
Date: 
Message-ID: <ey3znq25v2x.fsf@cley.com>
* 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
From: Wolfhard Buß
Subject: Re: format directive
Date: 
Message-ID: <m3bs2i7bax.fsf@buss-14250.user.cis.dfn.de>
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)
From: Thomas A. Russ
Subject: Re: format directive
Date: 
Message-ID: <ymid6mm7yry.fsf@sevak.isi.edu>
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