All Manuals > Common Lisp Interface Manager 2.0 User's Guide > Chapter 17 Formatted Output > 17.1 Formatting Tables in CLIM > 17.1.3 Examples of Formatting Tables

NextPrevUpTopContentsIndex

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)
                      y-spacing x-spacing) 
  (clim:formatting-table 
       (stream :y-spacing y-spacing                                  
            :x-spacing x-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 :y-spacing

Figure 24. shows the result of evaluating the example1 function call without providing the :y-spacing and :x-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 :x-spacing 10         
          :y-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 :y-spacing

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


Common Lisp Interface Manager 2.0 User's Guide - 3 Mar 2015

NextPrevUpTopContentsIndex