Next Prev Up Top Contents Index

17.1.3.1 Formatting a Table From a List

The example1 function formats a simple table whose contents come from a list.

(defvar *alphabet* '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
 
(defun example1 (&optional (items *alphabet*)   
                 &key (stream *standard-output*) (n-columns 6)
                      inter-row-spacing inter-column-spacing)
  (clim:formatting-table
       (stream :inter-row-spacing inter-row-spacing                                 
            :inter-column-spacing inter-column-spacing)
   (do ()
       ((null items))
     (clim:formatting-row (stream) 
       (do ((i 0 (1+ i)))
           ((or (null items) (= i n-columns))) 
         (clim:formatting-cell (stream)
           (format stream "~A" (pop items))))))))

Evaluating (example1 *alphabet* :stream *my-window*) shows this table:

     A B C D E F
     G H I J K L
     M N O P Q R
     S T U V W X
     Y Z
Figure 24. Example1 With No :inter-row-spacing

Figure 24. shows the result of evaluating the example1 function call without providing the :inter-row-spacing and :inter-column-spacing keywords. The defaults for these keywords makes tables whose elements are characters look reasonable.

You can easily vary the number of columns, and the spacing between rows or between columns. In the following example, we provide keyword arguments that change the appearance of the table.

Evaluating this form

(example1 *alphabet* :stream *my-window*
          :n-columns 10 :inter-column-spacing 10        
          :inter-row-spacing 10)

shows this table:

     A  B  C  D  E  F  G  H  I  J
     K  L  M  N  O  P  Q  R  S  T
     U  V  W  X  Y  Z
Figure 25. Example1 With :inter-row-spacing

(Note that this example can be done with formatting-item-list as shown in example4 .)


Common Lisp Interface Manager 2.0 User Guide - 14 Dec 2001

Next Prev Up Top Contents Index