[Openmcl-devel] Building tables with format

Hamilton Link hamlink at comcast.net
Tue Aug 17 20:56:04 PDT 2004


Wow, good question! I love format. Mind you I never write a format 
control string without CLTL2 handy...

After much searching, and deciding there was no straightforward way of 
doing as you yourself discovered, I revisited the pretty printing 
chapter of CLTL2. I think ~/.../ may do what you need. Look in section 
27.4 of CLTL2, and check this out:

? (defun chop (s arg &optional colonp atsignp &rest parameters)
   (print s)
   (print arg)
   (print colonp)
   (print atsignp)
   (print parameters)
   (let ((full-result (format nil "~a" arg)))
     (format s "~a" (subseq full-result 0 (min 10 (length 
full-result))))))
CHOP
? (format nil "~1,2,3:@/CHOP/" "This string is far, far too long!")
;; this was all my debugging output
#<STRING-OUTPUT-STREAM #x8155244E>
"This string is far, far too long!"
T
T
(1 2 3)
;; this was what was printed by the format command, using CHOP
"This strin"
?

And of course you could make chop take minlength, maxlength, and 
padchar as parameters and DWYM.

h

On Aug 17, 2004, at 10:06 AM, Camille Troillard wrote:

> Hello,
>
> I fear my question is a little bit off topic.
>
> I would like to output a table with fixed-width cells.  This means I 
> need to truncate string arguments in order to keep the cell width 
> constant.  FORMAT offers a way to add a padding, but there is not way 
> to truncate a string argument (I would have used an option to the ~A 
> or ~S directives).
>
> Is there any way to extend OpenMCL's FORMAT mechanism in order to do 
> just that?
>
>
> Thanks for your help,
> Camille
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>




More information about the Openmcl-devel mailing list