From: Peter Seibel
Subject: More trying to grok FORMAT, ~A padding control now.
Date: 
Message-ID: <m3d5y0i4a9.fsf@javamonkey.com>
Now I'm trying to understand the rationale behind the prefix
parameters to the ~A (and ~S) FORMAT directives. I get *how* it works
but I'm having a hard time figuring out what actual problem the
combination of mincol, colinc, and minpad solves. As in, some kind of
problem statement of the form "I want to output this object in X
columns unless Y in which case I want Z." Any FORMAT guru's out there
that can point me toward enlightenment.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp

From: Szymon
Subject: Re: More trying to grok FORMAT, ~A padding control now.
Date: 
Message-ID: <87d5y0tb3b.fsf@eva.rplacd.net>
Peter Seibel <·····@javamonkey.com> writes:

> Now I'm trying to understand the rationale behind the prefix
> parameters to the ~A (and ~S) FORMAT directives. I get *how* it works
> but I'm having a hard time figuring out what actual problem the
> combination of mincol, colinc, and minpad solves. As in, some kind of
> problem statement of the form "I want to output this object in X
> columns unless Y in which case I want Z." Any FORMAT guru's out there
> that can point me toward enlightenment.

BTW, Do you read this? ==>

o Waters, Richard C. XP: A Common Lisp Pretty Printing System. AI Memo 1102. 
  MIT Artificial Intelligence Laboratory.

o "Using the New Common Lisp Pretty Printer"
  ACM Lisp Pointers 5(2):27-34, April 1992
  by Richard C. Waters.

Regards, Szymon.
From: Peter Seibel
Subject: Re: More trying to grok FORMAT, ~A padding control now.
Date: 
Message-ID: <m38y8ohuzm.fsf@javamonkey.com>
Szymon <············@o2.pl> writes:

> Peter Seibel <·····@javamonkey.com> writes:
>
>> Now I'm trying to understand the rationale behind the prefix
>> parameters to the ~A (and ~S) FORMAT directives. I get *how* it works
>> but I'm having a hard time figuring out what actual problem the
>> combination of mincol, colinc, and minpad solves. As in, some kind of
>> problem statement of the form "I want to output this object in X
>> columns unless Y in which case I want Z." Any FORMAT guru's out there
>> that can point me toward enlightenment.
>
> BTW, Do you read this? ==>
>
> o Waters, Richard C. XP: A Common Lisp Pretty Printing System. AI Memo 1102. 
>   MIT Artificial Intelligence Laboratory.

I read this one a while back. I don't think ~A, et al. are really part
of the pretty printer however.

> o "Using the New Common Lisp Pretty Printer"
>   ACM Lisp Pointers 5(2):27-34, April 1992
>   by Richard C. Waters.

I'll have to look that one up. Thanks.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Szymon
Subject: Re: More trying to grok FORMAT, ~A padding control now.
Date: 
Message-ID: <87u0rbr33v.fsf@eva.rplacd.net>
Peter Seibel <·····@javamonkey.com> writes:

> > o "Using the New Common Lisp Pretty Printer"
> >   ACM Lisp Pointers 5(2):27-34, April 1992
> >   by Richard C. Waters.
> 
> I'll have to look that one up. Thanks.

I just found a link. This is three-part article which contains "Using the New
Common Lisp Pretty Printer" (in chapter 1).

http://www.merl.com/publications/TR1993-017/

Regards, Szymon.

ps. http://www.merl.com/publications/TR1991-004/
is OT, but nice too.
From: Carl Taylor
Subject: Re: More trying to grok FORMAT, ~A padding control now.
Date: 
Message-ID: <Ov3qd.986249$Gx4.197893@bgtnsc04-news.ops.worldnet.att.net>
Peter Seibel wrote:
> Now I'm trying to understand the rationale behind the prefix
> parameters to the ~A (and ~S) FORMAT directives. I get *how* it works
> but I'm having a hard time figuring out what actual problem the
> combination of mincol, colinc, and minpad solves. As in, some kind of
> problem statement of the form "I want to output this object in X
> columns unless Y in which case I want Z." Any FORMAT guru's out there
> that can point me toward enlightenment.

I've used the full form of ~A as a means to pad and format long strings.
For example:

(defun prt-grps-of-n (n in-string &key (colcnt 12))
    (assert (typep n '(integer 1 15)) (n)
                   "First argument <~S> s/b an integer in {1..15}." n)
    (assert (stringp in-string) (in-string)
                   "Second argument <~S> must be a string." in-string)
    (assert (typep colcnt '(integer 1 25)) (colcnt)
                   "Keyword parameter :colcnt <~S> s/b an integer in 
{1..25}." colcnt)
    (flet ((print-n (k s-obj)
               (format t
                       "~:[~;~%~]~3T~V,1,1,'*A "
                       (zerop (mod (* n k) (* n colcnt)))  n  s-obj)))
        (let* ((s-pointer   0)
               (s-length    (length in-string))
               (loop-count  (floor s-length n))
               (s-lng-tally s-length))
           (dotimes (i loop-count)
               (print-n
                      i
                      (subseq in-string s-pointer (+ s-pointer n)))
               (incf s-pointer n)
               (decf s-lng-tally n))
           (unless (zerop s-lng-tally)
               (print-n
                      (if (< s-length n) 0 loop-count)
                      (subseq in-string s-pointer s-length)))))
    (values))


CL-USER 14 > (prt-grps-of-n 5  (make-string 101 :initial-element #\5) 
:colcnt 10)

   55555  55555  55555  55555  55555  55555  55555  55555  55555  55555
   55555  55555  55555  55555  55555  55555  55555  55555  55555  55555
   5****

CL-USER 15 > (prt-grps-of-n 3  (make-string 101 :initial-element #\X) 
:colcnt 8)

   XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX
   XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX
   XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX
   XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX
   XXX  XX*

Carl Taylor
From: Peter Seibel
Subject: Re: More trying to grok FORMAT, ~A padding control now.
Date: 
Message-ID: <m3fz2vgkpl.fsf@javamonkey.com>
"Carl Taylor" <··········@att.net> writes:

> Peter Seibel wrote:
>> Now I'm trying to understand the rationale behind the prefix
>> parameters to the ~A (and ~S) FORMAT directives. I get *how* it works
>> but I'm having a hard time figuring out what actual problem the
>> combination of mincol, colinc, and minpad solves. As in, some kind of
>> problem statement of the form "I want to output this object in X
>> columns unless Y in which case I want Z." Any FORMAT guru's out there
>> that can point me toward enlightenment.
>
> I've used the full form of ~A as a means to pad and format long
> strings. For example:

[snip]

Okay. So I notice you still use colinc of 1. I get why a minimum
padding could be useful: to keep things from running together. But I'm
having a hard time understanding when I'd ever say: okay, so if the
natural width of the output plus the required padding still isn't wide
enough I want to add padding in chunks of N so that the final width of
the output will end up being essentially (+ mincol (random colinc)).
Obviously it's not actually random but dependent on the natural width
of the output plus the minimum padding, but it might as well be.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp