From: Chris Kacoroski,none
Subject: Use of format or pprint
Date: 
Message-ID: <1992Dec17.173558.18552@grace.boeing.com>
Hi,

I need help in figuring out a format statement.

(setq a "org")
(setq b "chris dan ski elaine nick tony charlie jeff jeffw bruce mike kim kelly")

or a list of names

(setq b '("chris" "dan" "ski"...))

What format string

(format "???" a b)

will print them in this format

org:	chris dan ski elaine nick tony charlie
	jeff jeffw bruce mike kim kelly



Thanks in advance


Cheers,

Chris "ski" Kacoroski	"When we try to pick out anything by itself
···@atc.boeing.com	 we find it connected to the entire universe"
							John Muir

From: Barry Margolin
Subject: Re: Use of format or pprint
Date: 
Message-ID: <1gtulrINN3gr@early-bird.think.com>
In article <······················@grace.boeing.com> ···@atc.boeing.com writes:
>(setq a "org")
>(setq b "chris dan ski elaine nick tony charlie jeff jeffw bruce mike kim kelly")
>
>or a list of names
>
>(setq b '("chris" "dan" "ski"...))

You'll have to write your own routine to convert the single-string form
into a list of strings.  Common Lisp has nothing that will parse the string
into words and treat them separately for this purpose (the only thing in CL
that deals with words is STRING-CAPITALIZE).

>What format string will print them in this format
>
>org:	chris dan ski elaine nick tony charlie
>	jeff jeffw bruce mike kim kelly

Once you've got a list of words in B, you can make use of the ~<...~:;...~>
FORMAT directive to fill the line with them.

(format t "~&~A:~7T~{~<~%~7T~:; ~A~>~}~%" a b)

This is similar to the example in CLtL for printing a comma-separated list
of items.
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar
From: William Fitzgerald
Subject: Re: Use of format or pprint
Date: 
Message-ID: <1992Dec21.224457.23526@ils.nwu.edu>
Barry Margolin (······@think.com) wrote:
: 
: You'll have to write your own routine to convert the single-string form
: into a list of strings.  Common Lisp has nothing that will parse the string
: into words and treat them separately for this purpose (the only thing in CL
: that deals with words is STRING-CAPITALIZE).
: 

Here are some functions I've written to convert strings into lists of
various sorts. Examples follow at the end.

(defun list-from-string (string
                         &key 
                         (start 0) 
                         (char-bag '(#\Space))
                         (test #'(lambda (ch)
                                   (not (member ch char-bag 
                                                :test 'char=))))
                         (post-process 'identity))
  (let ((pos (position-if test string :start start)))
    (if pos 
      (list-from-string* string :start  pos :char-bag char-bag
                         :test test :post-process post-process)
      nil)))

(defun list-from-string* (string
                          &key 
                          (start 0) 
                          (char-bag '(#\Space))
                          (test #'(lambda (ch)
                                    (not (member ch char-bag :test 'char=))))
                          (post-process 'identity))
  (let* ((pos (position-if-not test string :start start))
         (new-pos (if pos (position-if test string :start pos) nil)))
    (cond
     ((and pos new-pos)
      (cons (funcall post-process (subseq string start pos))
            (list-from-string* string :start new-pos :char-bag char-bag
                               :test test :post-process post-process)))
     (pos (list (funcall post-process (subseq string start pos))))
     
     (t (list (funcall post-process (subseq string start)))))))


(defmethod string->symbol-list ((s string) &optional (package *package*))
  (list-from-string s :post-process
                    #'(lambda (str) 
                        (intern (nstring-upcase str) package))
                    :test 'alphanumericp))



#|


(list-from-string  "chris dan ski elaine nick") --> 
  ("chris" "dan" "ski" "elaine" "nick")

(list-from-string  "chris dan ski elaine nick" 
                   :post-process 'nstring-capitalize) -->
  ("Chris" "Dan" "Ski" "Elaine" "Nick")

(list-from-string "chris! dan! ski! elaine! nick!"
                  :char-bag '(#\Space #\!)) -->
  ("chris" "dan" "ski" "elaine" "nick")

(string->symbol-list "chris dan ski elaine nick")-->
 (CHRIS DAN SKI ELAINE NICK)


|#
From: William Fitzgerald
Subject: Re: Use of format or pprint
Date: 
Message-ID: <1992Dec21.143856.28329@ils.nwu.edu>
Chris Kacoroski,none (···@atc.boeing.com) wrote:
: Hi,
: 
: I need help in figuring out a format statement.
: 
: 
: What format string
: 
: 
: will print them in this format
: 
: org:	chris dan ski elaine nick tony charlie
: 	jeff jeffw bruce mike kim kelly
: 

See the FAQ [3-14], which gives a template for this type of printing.
From: Tom Kramer
Subject: Re: Use of format or pprint
Date: 
Message-ID: <20483@cosmos.cme.nist.gov>
In article <······················@grace.boeing.com> ···@atc.boeing.com writes:

>(setq a "org")
>(setq b 
>  "chris dan ski elaine nick tony charlie jeff jeffw bruce mike kim kelly")
>or (setq b '("chris" "dan" "ski"...))
>
>What format string
>(format "???" a b)
>will print them in this format
>
>org:	chris dan ski elaine nick tony charlie
>	jeff jeffw bruce mike kim kelly

Using (setq b '("chris" "dan" "ski" ...)) the following works

(format t "~A:~{~8T~A~^ ~A~^ ~A~^ ~A~^ ~A~^ ~A~^ ~A~^~%~}" a b)

The first ~A uses up a.
The ~{...~} is processed repeatedly on elements of b until all are used.
The 8T gets to the correct column.
The ~^ are so processing will stop without error regardless of the
length of b.

I wasted an hour on that, but I learned something. Merry Christmas!
This worked in Allegro Common LISP on a SUN4.

Tom Kramer
······@cme.nist.gov
From: Bill York
Subject: Re: Use of format or pprint
Date: 
Message-ID: <YORK.92Dec24124001@oakland-hills.lucid.com>
In article <·····@cosmos.cme.nist.gov> ······@cme.nist.gov (Tom Kramer) writes:

   In article <······················@grace.boeing.com> ···@atc.boeing.com writes:

   >What format string
   >(format "???" a b)
   >will print them in this format
   >
   >org:	chris dan ski elaine nick tony charlie
   >	jeff jeffw bruce mike kim kelly

   Using (setq b '("chris" "dan" "ski" ...)) the following works

   (format t "~A:~{~8T~A~^ ~A~^ ~A~^ ~A~^ ~A~^ ~A~^ ~A~^~%~}" a b)
   I wasted an hour on that, but I learned something. Merry Christmas!

To paraphrase the old TECO joke:

"FORMAT.  A moment of convenience.  A lifetime of regret."