Saturday, June 05, 2004

More Format Directives

A friend of mine Jorg Preisendorfer, came across my entries on format directives. The modifiers for iteration as mentioned in section 22.3.7.4 of CLHS. I had discovered "~{" and "~}" directives. Here are the more elegant rewrites.

My code

(format t "~{~{~A~%~A~%~}~}" '((a b) (c d) (e f) (g h)))


The better version

(format t "~:{~A~%~A~%~}" '((a b) (c d) (e f) (g h)))

More succinct, and easier to write. The colon performs the iteration on sublists.

Another directive that I had discovered was "~R" which prints a number in the English formulation. I had also requested a Loop version mainly because of my inexperience with Loop. Here is the code.

(loop for x = (expt 10 9) then (* x 1000)
until (>= x (expt 10 66))
do (format t "~R = ~:*~A~%" x))


The directive "~:*" directive is also very interesting as mentioned in section 22.3.7.1 of the CLHS.

Thanks for the responses Jorg.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home