[cl-who-devel] Building a table from a list of strings - Can't seem to get it right

Ken Harris kengruven at gmail.com
Tue Jun 16 06:49:07 UTC 2009


Hi Bryan,

cl-who does have limitations, and one of them I've found is that it
works best if you know a priori the structure you're generating.
Putting items into a table in HTML, unfortunately, doesn't quite have
this property.

Still, you can certainly use it for that, especially if you don't mind
nesting loops -- maybe something like:

(defun gridify (x &optional (col 5))
  "given a list of strings, put them in an html table (returned as a
string) with |col| columns."
  (with-html-output-to-string (var nil)
    (:table
      (loop for xp on x by (lambda (p) (nthcdr col p))
        do (htm (:tr (loop for i upto (1- col) for xi in xp
                       do (htm (:td (str xi))))))))))

(gridify (loop for i from 1 upto 50 collect (format nil "cell #~D" i)))


cheers,

- Ken




More information about the Cl-who-devel mailing list