rlm@10: ;;; cl_format.clj -- part of the pretty printer for Clojure rlm@10: rlm@10: ;; by Tom Faulhaber rlm@10: ;; April 3, 2009 rlm@10: rlm@10: ; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved. rlm@10: ; The use and distribution terms for this software are covered by the rlm@10: ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) rlm@10: ; which can be found in the file epl-v10.html at the root of this distribution. rlm@10: ; By using this software in any fashion, you are agreeing to be bound by rlm@10: ; the terms of this license. rlm@10: ; You must not remove this notice, or any other, from this software. rlm@10: rlm@10: ;; This test set tests the basic cl-format functionality rlm@10: rlm@10: (ns clojure.contrib.pprint.test-cl-format rlm@10: (:refer-clojure :exclude [format]) rlm@10: (:use [clojure.test :only (deftest are run-tests)] rlm@10: clojure.contrib.pprint.test-helper rlm@10: clojure.contrib.pprint)) rlm@10: rlm@10: (def format cl-format) rlm@10: rlm@10: ;; TODO tests for ~A, ~D, etc. rlm@10: ;; TODO add tests for ~F, etc.: 0.0, 9.9999 with rounding, 9.9999E99 with rounding rlm@10: rlm@10: (simple-tests d-tests rlm@10: (cl-format nil "~D" 0) "0" rlm@10: (cl-format nil "~D" 2e6) "2000000" rlm@10: (cl-format nil "~D" 2000000) "2000000" rlm@10: (cl-format nil "~:D" 2000000) "2,000,000" rlm@10: (cl-format nil "~D" 1/2) "1/2" rlm@10: (cl-format nil "~D" 'fred) "fred" rlm@10: ) rlm@10: rlm@10: (simple-tests base-tests rlm@10: (cl-format nil "~{~2r~^ ~}~%" (range 10)) rlm@10: "0 1 10 11 100 101 110 111 1000 1001\n" rlm@10: (with-out-str rlm@10: (dotimes [i 35] rlm@10: (binding [*print-base* (+ i 2)] ;print the decimal number 40 rlm@10: (write 40) ;in each base from 2 to 36 rlm@10: (if (zero? (mod i 10)) (prn) (cl-format true " "))))) rlm@10: "101000 rlm@10: 1111 220 130 104 55 50 44 40 37 34 rlm@10: 31 2c 2a 28 26 24 22 20 1j 1i rlm@10: 1h 1g 1f 1e 1d 1c 1b 1a 19 18 rlm@10: 17 16 15 14 " rlm@10: (with-out-str rlm@10: (doseq [pb [2 3 8 10 16]] rlm@10: (binding [*print-radix* true ;print the integer 10 and rlm@10: *print-base* pb] ;the ratio 1/10 in bases 2, rlm@10: (cl-format true "~&~S ~S~%" 10 1/10)))) ;3, 8, 10, 16 rlm@10: "#b1010 #b1/1010 rlm@10: #3r101 #3r1/101 rlm@10: #o12 #o1/12 rlm@10: 10. #10r1/10 rlm@10: #xa #x1/a rlm@10: ") rlm@10: rlm@10: rlm@10: rlm@10: (simple-tests cardinal-tests rlm@10: (cl-format nil "~R" 0) "zero" rlm@10: (cl-format nil "~R" 4) "four" rlm@10: (cl-format nil "~R" 15) "fifteen" rlm@10: (cl-format nil "~R" -15) "minus fifteen" rlm@10: (cl-format nil "~R" 25) "twenty-five" rlm@10: (cl-format nil "~R" 20) "twenty" rlm@10: (cl-format nil "~R" 200) "two hundred" rlm@10: (cl-format nil "~R" 203) "two hundred three" rlm@10: rlm@10: (cl-format nil "~R" 44879032) rlm@10: "forty-four million, eight hundred seventy-nine thousand, thirty-two" rlm@10: rlm@10: (cl-format nil "~R" -44879032) rlm@10: "minus forty-four million, eight hundred seventy-nine thousand, thirty-two" rlm@10: rlm@10: (cl-format nil "~R = ~:*~:D" 44000032) rlm@10: "forty-four million, thirty-two = 44,000,032" rlm@10: rlm@10: (cl-format nil "~R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094) rlm@10: "four hundred forty-eight septendecillion, seven hundred ninety sexdecillion, three hundred twenty-nine quindecillion, four hundred eighty quattuordecillion, nine hundred forty-eight tredecillion, two hundred nine duodecillion, three hundred eighty-four undecillion, three hundred eighty-nine decillion, four hundred twenty-nine nonillion, three hundred eighty-four octillion, twenty-nine septillion, three hundred eighty-four sextillion, twenty-nine quintillion, eight hundred forty-two quadrillion, ninety-eight trillion, four hundred twenty billion, nine hundred eighty-nine million, eight hundred forty-two thousand, ninety-four = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094" rlm@10: rlm@10: (cl-format nil "~R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094490320942058747587584758375847593475) rlm@10: "448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475 = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475" rlm@10: rlm@10: (cl-format nil "~R = ~:*~:D" 2e6) rlm@10: "two million = 2,000,000" rlm@10: rlm@10: (cl-format nil "~R = ~:*~:D" 200000200000) rlm@10: "two hundred billion, two hundred thousand = 200,000,200,000") rlm@10: rlm@10: (simple-tests ordinal-tests rlm@10: (cl-format nil "~:R" 0) "zeroth" rlm@10: (cl-format nil "~:R" 4) "fourth" rlm@10: (cl-format nil "~:R" 15) "fifteenth" rlm@10: (cl-format nil "~:R" -15) "minus fifteenth" rlm@10: (cl-format nil "~:R" 25) "twenty-fifth" rlm@10: (cl-format nil "~:R" 20) "twentieth" rlm@10: (cl-format nil "~:R" 200) "two hundredth" rlm@10: (cl-format nil "~:R" 203) "two hundred third" rlm@10: rlm@10: (cl-format nil "~:R" 44879032) rlm@10: "forty-four million, eight hundred seventy-nine thousand, thirty-second" rlm@10: rlm@10: (cl-format nil "~:R" -44879032) rlm@10: "minus forty-four million, eight hundred seventy-nine thousand, thirty-second" rlm@10: rlm@10: (cl-format nil "~:R = ~:*~:D" 44000032) rlm@10: "forty-four million, thirty-second = 44,000,032" rlm@10: rlm@10: (cl-format nil "~:R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094) rlm@10: "four hundred forty-eight septendecillion, seven hundred ninety sexdecillion, three hundred twenty-nine quindecillion, four hundred eighty quattuordecillion, nine hundred forty-eight tredecillion, two hundred nine duodecillion, three hundred eighty-four undecillion, three hundred eighty-nine decillion, four hundred twenty-nine nonillion, three hundred eighty-four octillion, twenty-nine septillion, three hundred eighty-four sextillion, twenty-nine quintillion, eight hundred forty-two quadrillion, ninety-eight trillion, four hundred twenty billion, nine hundred eighty-nine million, eight hundred forty-two thousand, ninety-fourth = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094" rlm@10: (cl-format nil "~:R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094490320942058747587584758375847593475) rlm@10: "448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475th = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475" rlm@10: (cl-format nil "~:R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094490320942058747587584758375847593471) rlm@10: "448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,471st = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,471" rlm@10: (cl-format nil "~:R = ~:*~:D" 2e6) rlm@10: "two millionth = 2,000,000") rlm@10: rlm@10: (simple-tests ordinal1-tests rlm@10: (cl-format nil "~:R" 1) "first" rlm@10: (cl-format nil "~:R" 11) "eleventh" rlm@10: (cl-format nil "~:R" 21) "twenty-first" rlm@10: (cl-format nil "~:R" 20) "twentieth" rlm@10: (cl-format nil "~:R" 220) "two hundred twentieth" rlm@10: (cl-format nil "~:R" 200) "two hundredth" rlm@10: (cl-format nil "~:R" 999) "nine hundred ninety-ninth" rlm@10: ) rlm@10: rlm@10: (simple-tests roman-tests rlm@10: (cl-format nil "~@R" 3) "III" rlm@10: (cl-format nil "~@R" 4) "IV" rlm@10: (cl-format nil "~@R" 9) "IX" rlm@10: (cl-format nil "~@R" 29) "XXIX" rlm@10: (cl-format nil "~@R" 429) "CDXXIX" rlm@10: (cl-format nil "~@:R" 429) "CCCCXXVIIII" rlm@10: (cl-format nil "~@:R" 3429) "MMMCCCCXXVIIII" rlm@10: (cl-format nil "~@R" 3429) "MMMCDXXIX" rlm@10: (cl-format nil "~@R" 3479) "MMMCDLXXIX" rlm@10: (cl-format nil "~@R" 3409) "MMMCDIX" rlm@10: (cl-format nil "~@R" 300) "CCC" rlm@10: (cl-format nil "~@R ~D" 300 20) "CCC 20" rlm@10: (cl-format nil "~@R" 5000) "5,000" rlm@10: (cl-format nil "~@R ~D" 5000 20) "5,000 20" rlm@10: (cl-format nil "~@R" "the quick") "the quick") rlm@10: rlm@10: (simple-tests c-tests rlm@10: (cl-format nil "~{~c~^, ~}~%" "hello") "h, e, l, l, o\n" rlm@10: (cl-format nil "~{~:c~^, ~}~%" "hello") "h, e, l, l, o\n" rlm@10: (cl-format nil "~@C~%" \m) "\\m\n" rlm@10: (cl-format nil "~@C~%" (char 222)) "\\Þ\n" rlm@10: (cl-format nil "~@C~%" (char 8)) "\\backspace\n" rlm@10: (cl-format nil "~@C~%" (char 3)) "\\\n") rlm@10: rlm@10: (simple-tests e-tests rlm@10: (cl-format nil "*~E*" 0.0) "*0.0E+0*" rlm@10: (cl-format nil "*~6E*" 0.0) "*0.0E+0*" rlm@10: (cl-format nil "*~6,0E*" 0.0) "* 0.E+0*" rlm@10: (cl-format nil "*~7,2E*" 0.0) "*0.00E+0*" rlm@10: (cl-format nil "*~5E*" 0.0) "*0.E+0*" rlm@10: (cl-format nil "*~10,2,2,,'?E*" 2.8E120) "*??????????*" rlm@10: (cl-format nil "*~10,2E*" 9.99999) "* 1.00E+1*" rlm@10: (cl-format nil "*~10,2E*" 9.99999E99) "* 1.00E+100*" rlm@10: (cl-format nil "*~10,2,2E*" 9.99999E99) "* 1.00E+100*" rlm@10: (cl-format nil "*~10,2,2,,'?E*" 9.99999E99) "*??????????*" rlm@10: ) rlm@10: rlm@10: (simple-tests $-tests rlm@10: (cl-format nil "~$" 22.3) "22.30" rlm@10: (cl-format nil "~$" 22.375) "22.38" rlm@10: (cl-format nil "~3,5$" 22.375) "00022.375" rlm@10: (cl-format nil "~3,5,8$" 22.375) "00022.375" rlm@10: (cl-format nil "~3,5,10$" 22.375) " 00022.375" rlm@10: (cl-format nil "~3,5,14@$" 22.375) " +00022.375" rlm@10: (cl-format nil "~3,5,14@$" 22.375) " +00022.375" rlm@10: (cl-format nil "~3,5,14@:$" 22.375) "+ 00022.375" rlm@10: (cl-format nil "~3,,14@:$" 0.375) "+ 0.375" rlm@10: (cl-format nil "~1,1$" -12.0) "-12.0" rlm@10: (cl-format nil "~1,1$" 12.0) "12.0" rlm@10: (cl-format nil "~1,1$" 12.0) "12.0" rlm@10: (cl-format nil "~1,1@$" 12.0) "+12.0" rlm@10: (cl-format nil "~1,1,8,' @:$" 12.0) "+ 12.0" rlm@10: (cl-format nil "~1,1,8,' @$" 12.0) " +12.0" rlm@10: (cl-format nil "~1,1,8,' :$" 12.0) " 12.0" rlm@10: (cl-format nil "~1,1,8,' $" 12.0) " 12.0" rlm@10: (cl-format nil "~1,1,8,' @:$" -12.0) "- 12.0" rlm@10: (cl-format nil "~1,1,8,' @$" -12.0) " -12.0" rlm@10: (cl-format nil "~1,1,8,' :$" -12.0) "- 12.0" rlm@10: (cl-format nil "~1,1,8,' $" -12.0) " -12.0" rlm@10: (cl-format nil "~1,1$" 0.001) "0.0" rlm@10: (cl-format nil "~2,1$" 0.001) "0.00" rlm@10: (cl-format nil "~1,1,6$" 0.001) " 0.0" rlm@10: (cl-format nil "~1,1,6$" 0.0015) " 0.0" rlm@10: (cl-format nil "~2,1,6$" 0.005) " 0.01" rlm@10: (cl-format nil "~2,1,6$" 0.01) " 0.01" rlm@10: (cl-format nil "~$" 0.099) "0.10" rlm@10: (cl-format nil "~1$" 0.099) "0.1" rlm@10: (cl-format nil "~1$" 0.1) "0.1" rlm@10: (cl-format nil "~1$" 0.99) "1.0" rlm@10: (cl-format nil "~1$" -0.99) "-1.0") rlm@10: rlm@10: (simple-tests f-tests rlm@10: (cl-format nil "~,1f" -12.0) "-12.0" rlm@10: (cl-format nil "~,0f" 9.4) "9." rlm@10: (cl-format nil "~,0f" 9.5) "10." rlm@10: (cl-format nil "~,0f" -0.99) "-1." rlm@10: (cl-format nil "~,1f" -0.99) "-1.0" rlm@10: (cl-format nil "~,2f" -0.99) "-0.99" rlm@10: (cl-format nil "~,3f" -0.99) "-0.990" rlm@10: (cl-format nil "~,0f" 0.99) "1." rlm@10: (cl-format nil "~,1f" 0.99) "1.0" rlm@10: (cl-format nil "~,2f" 0.99) "0.99" rlm@10: (cl-format nil "~,3f" 0.99) "0.990" rlm@10: (cl-format nil "~f" -1) "-1.0" rlm@10: (cl-format nil "~2f" -1) "-1." rlm@10: (cl-format nil "~3f" -1) "-1." rlm@10: (cl-format nil "~4f" -1) "-1.0" rlm@10: (cl-format nil "~8f" -1) " -1.0" rlm@10: (cl-format nil "~1,1f" 0.1) ".1") rlm@10: rlm@10: (simple-tests ampersand-tests rlm@10: (cl-format nil "The quick brown ~a jumped over ~d lazy dogs" 'elephant 5) rlm@10: "The quick brown elephant jumped over 5 lazy dogs" rlm@10: (cl-format nil "The quick brown ~&~a jumped over ~d lazy dogs" 'elephant 5) rlm@10: "The quick brown \nelephant jumped over 5 lazy dogs" rlm@10: (cl-format nil "The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5) rlm@10: "The quick brown \nelephant jumped\n over 5 lazy dogs" rlm@10: (cl-format nil "~&The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5) rlm@10: "The quick brown \nelephant jumped\n over 5 lazy dogs" rlm@10: (cl-format nil "~3&The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5) rlm@10: "\n\nThe quick brown \nelephant jumped\n over 5 lazy dogs" rlm@10: (cl-format nil "~@{~&The quick brown ~a jumped over ~d lazy dogs~}" 'elephant 5 'fox 10) rlm@10: "The quick brown elephant jumped over 5 lazy dogs\nThe quick brown fox jumped over 10 lazy dogs" rlm@10: (cl-format nil "I ~[don't ~:;d~&o ~]have one~%" 0) "I don't have one\n" rlm@10: (cl-format nil "I ~[don't ~:;d~&o ~]have one~%" 1) "I d\no have one\n") rlm@10: rlm@10: (simple-tests t-tests rlm@10: (cl-format nil "~@{~&~A~8,4T~:*~A~}" rlm@10: 'a 'aa 'aaa 'aaaa 'aaaaa 'aaaaaa 'aaaaaaa 'aaaaaaaa 'aaaaaaaaa 'aaaaaaaaaa) rlm@10: "a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa" rlm@10: (cl-format nil "~@{~&~A~,4T~:*~A~}" rlm@10: 'a 'aa 'aaa 'aaaa 'aaaaa 'aaaaaa 'aaaaaaa 'aaaaaaaa 'aaaaaaaaa 'aaaaaaaaaa) rlm@10: "a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa" rlm@10: (cl-format nil "~@{~&~A~2,6@T~:*~A~}" 'a 'aa 'aaa 'aaaa 'aaaaa 'aaaaaa 'aaaaaaa 'aaaaaaaa 'aaaaaaaaa 'aaaaaaaaaa) rlm@10: "a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa" rlm@10: ) rlm@10: rlm@10: (simple-tests paren-tests rlm@10: (cl-format nil "~(PLEASE SPEAK QUIETLY IN HERE~)") "please speak quietly in here" rlm@10: (cl-format nil "~@(PLEASE SPEAK QUIETLY IN HERE~)") "Please speak quietly in here" rlm@10: (cl-format nil "~@:(but this Is imporTant~)") "BUT THIS IS IMPORTANT" rlm@10: (cl-format nil "~:(the greAt gatsby~)!") "The Great Gatsby!" rlm@10: ;; Test cases from CLtL 18.3 - string-upcase, et al. rlm@10: (cl-format nil "~@:(~A~)" "Dr. Livingstone, I presume?") "DR. LIVINGSTONE, I PRESUME?" rlm@10: (cl-format nil "~(~A~)" "Dr. Livingstone, I presume?") "dr. livingstone, i presume?" rlm@10: (cl-format nil "~:(~A~)" " hello ") " Hello " rlm@10: (cl-format nil "~:(~A~)" "occlUDeD cASEmenTs FOreSTAll iNADVertent DEFenestraTION") rlm@10: "Occluded Casements Forestall Inadvertent Defenestration" rlm@10: (cl-format nil "~:(~A~)" 'kludgy-hash-search) "Kludgy-Hash-Search" rlm@10: (cl-format nil "~:(~A~)" "DON'T!") "Don'T!" ;not "Don't!" rlm@10: (cl-format nil "~:(~A~)" "pipe 13a, foo16c") "Pipe 13a, Foo16c" rlm@10: ) rlm@10: rlm@10: (simple-tests square-bracket-tests rlm@10: ;; Tests for format without modifiers rlm@10: (cl-format nil "I ~[don't ~]have one~%" 0) "I don't have one\n" rlm@10: (cl-format nil "I ~[don't ~]have one~%" 1) "I have one\n" rlm@10: (cl-format nil "I ~[don't ~;do ~]have one~%" 0) "I don't have one\n" rlm@10: (cl-format nil "I ~[don't ~;do ~]have one~%" 1) "I do have one\n" rlm@10: (cl-format nil "I ~[don't ~;do ~]have one~%" 2) "I have one\n" rlm@10: (cl-format nil "I ~[don't ~:;do ~]have one~%" 0) "I don't have one\n" rlm@10: (cl-format nil "I ~[don't ~:;do ~]have one~%" 1) "I do have one\n" rlm@10: (cl-format nil "I ~[don't ~:;do ~]have one~%" 2) "I do have one\n" rlm@10: (cl-format nil "I ~[don't ~:;do ~]have one~%" 700) "I do have one\n" rlm@10: rlm@10: ;; Tests for format with a colon rlm@10: (cl-format nil "I ~:[don't ~;do ~]have one~%" true) "I do have one\n" rlm@10: (cl-format nil "I ~:[don't ~;do ~]have one~%" 700) "I do have one\n" rlm@10: (cl-format nil "I ~:[don't ~;do ~]have one~%" '(a b)) "I do have one\n" rlm@10: (cl-format nil "I ~:[don't ~;do ~]have one~%" nil) "I don't have one\n" rlm@10: (cl-format nil "I ~:[don't ~;do ~]have one~%" false) "I don't have one\n" rlm@10: rlm@10: ;; Tests for format with an at sign rlm@10: (cl-format nil "We had ~D wins~@[ (out of ~D tries)~].~%" 15 nil) "We had 15 wins.\n" rlm@10: (cl-format nil "We had ~D wins~@[ (out of ~D tries)~].~%" 15 17) rlm@10: "We had 15 wins (out of 17 tries).\n" rlm@10: rlm@10: ;; Format tests with directives rlm@10: (cl-format nil "Max ~D: ~[Blue team ~D~;Red team ~D~:;No team ~A~].~%" 15, 0, 7) rlm@10: "Max 15: Blue team 7.\n" rlm@10: (cl-format nil "Max ~D: ~[Blue team ~D~;Red team ~D~:;No team ~A~].~%" 15, 1, 12) rlm@10: "Max 15: Red team 12.\n" rlm@10: (cl-format nil "Max ~D: ~[Blue team ~D~;Red team ~D~:;No team ~A~].~%" rlm@10: 15, -1, "(system failure)") rlm@10: "Max 15: No team (system failure).\n" rlm@10: rlm@10: ;; Nested format tests rlm@10: (cl-format nil "Max ~D: ~[Blue team ~D~:[~; (complete success)~]~;Red team ~D~:;No team ~].~%" rlm@10: 15, 0, 7, true) rlm@10: "Max 15: Blue team 7 (complete success).\n" rlm@10: (cl-format nil "Max ~D: ~[Blue team ~D~:[~; (complete success)~]~;Red team ~D~:;No team ~].~%" rlm@10: 15, 0, 7, false) rlm@10: "Max 15: Blue team 7.\n" rlm@10: rlm@10: ;; Test the selector as part of the argument rlm@10: (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~].") rlm@10: "The answer is nothing." rlm@10: (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~]." 4) rlm@10: "The answer is 4." rlm@10: (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~]." 7 22) rlm@10: "The answer is 7 out of 22." rlm@10: (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~]." 1 2 3 4) rlm@10: "The answer is something crazy." rlm@10: ) rlm@10: rlm@10: (simple-tests curly-brace-plain-tests rlm@10: ;; Iteration from sublist rlm@10: (cl-format nil "Coordinates are~{ [~D,~D]~}~%" [ 0, 1, 1, 0, 3, 5, 2, 1 ]) rlm@10: "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~2{ [~D,~D]~}~%" [ 0, 1, 1, 0, 3, 5, 2, 1 ]) rlm@10: "Coordinates are [0,1] [1,0]\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~{ ~#[none~;<~D>~:;[~D,~D]~]~}~%" [ ]) rlm@10: "Coordinates are\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [ ]) rlm@10: "Coordinates are none\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [2 3 1]) rlm@10: "Coordinates are [2,3] <1>\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~{~:}~%" "" []) rlm@10: "Coordinates are\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [2 3 1]) rlm@10: "Coordinates are [2,3] <1>\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [ ]) rlm@10: "Coordinates are none\n" rlm@10: ) rlm@10: rlm@10: rlm@10: (simple-tests curly-brace-colon-tests rlm@10: ;; Iteration from list of sublists rlm@10: (cl-format nil "Coordinates are~:{ [~D,~D]~}~%" [ [0, 1], [1, 0], [3, 5], [2, 1] ]) rlm@10: "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~:{ [~D,~D]~}~%" [ [0, 1, 0], [1, 0, 12], [3, 5], [2, 1] ]) rlm@10: "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~2:{ [~D,~D]~}~%" [ [0, 1], [1, 0], [3, 5], [2, 1] ]) rlm@10: "Coordinates are [0,1] [1,0]\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~:{ ~#[none~;<~D>~:;[~D,~D]~]~}~%" [ ]) rlm@10: "Coordinates are\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [ ]) rlm@10: "Coordinates are none\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [[2 3] [1]]) rlm@10: "Coordinates are [2,3] <1>\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~:{~:}~%" "" []) rlm@10: "Coordinates are\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [[2 3] [1]]) rlm@10: "Coordinates are [2,3] <1>\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [ ]) rlm@10: "Coordinates are none\n" rlm@10: ) rlm@10: rlm@10: (simple-tests curly-brace-at-tests rlm@10: ;; Iteration from main list rlm@10: (cl-format nil "Coordinates are~@{ [~D,~D]~}~%" 0, 1, 1, 0, 3, 5, 2, 1) rlm@10: "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~2@{ [~D,~D]~}~%" 0, 1, 1, 0, 3, 5, 2, 1) rlm@10: "Coordinates are [0,1] [1,0]\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@{ ~#[none~;<~D>~:;[~D,~D]~]~}~%") rlm@10: "Coordinates are\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%") rlm@10: "Coordinates are none\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" 2 3 1) rlm@10: "Coordinates are [2,3] <1>\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@{~:}~%" "") rlm@10: "Coordinates are\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" 2 3 1) rlm@10: "Coordinates are [2,3] <1>\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]") rlm@10: "Coordinates are none\n" rlm@10: ) rlm@10: rlm@10: (simple-tests curly-brace-colon-at-tests rlm@10: ;; Iteration from sublists on the main arg list rlm@10: (cl-format nil "Coordinates are~@:{ [~D,~D]~}~%" [0, 1], [1, 0], [3, 5], [2, 1] ) rlm@10: "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@:{ [~D,~D]~}~%" [0, 1, 0], [1, 0, 12], [3, 5], [2, 1] ) rlm@10: "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~2@:{ [~D,~D]~}~%" [0, 1], [1, 0], [3, 5], [2, 1]) rlm@10: "Coordinates are [0,1] [1,0]\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@:{ ~#[none~;<~D>~:;[~D,~D]~]~}~%") rlm@10: "Coordinates are\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%") rlm@10: "Coordinates are none\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [2 3] [1]) rlm@10: "Coordinates are [2,3] <1>\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@:{~:}~%" "") rlm@10: "Coordinates are\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [2 3] [1]) rlm@10: "Coordinates are [2,3] <1>\n" rlm@10: rlm@10: (cl-format nil "Coordinates are~@:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]") rlm@10: "Coordinates are none\n" rlm@10: ) rlm@10: rlm@10: ;; TODO tests for ~^ in ~[ constructs and other brackets rlm@10: ;; TODO test ~:^ generates an error when used improperly rlm@10: ;; TODO test ~:^ works in ~@:{...~} rlm@10: (let [aseq '(a quick brown fox jumped over the lazy dog) rlm@10: lseq (mapcat identity (for [x aseq] [x (.length (name x))]))] rlm@10: (simple-tests up-tests rlm@10: (cl-format nil "~{~a~^, ~}" aseq) "a, quick, brown, fox, jumped, over, the, lazy, dog" rlm@10: (cl-format nil "~{~a~0^, ~}" aseq) "a" rlm@10: (cl-format nil "~{~a~#,3^, ~}" aseq) "a, quick, brown, fox, jumped, over" rlm@10: (cl-format nil "~{~a~v,3^, ~}" lseq) "a, quick, brown, fox" rlm@10: (cl-format nil "~{~a~3,v,4^, ~}" lseq) "a, quick, brown, fox" rlm@10: )) rlm@10: rlm@10: (simple-tests angle-bracket-tests rlm@10: (cl-format nil "~") "foobarbaz" rlm@10: (cl-format nil "~20") "foo bar baz" rlm@10: (cl-format nil "~,,2") "foo bar baz" rlm@10: (cl-format nil "~20<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz" rlm@10: (cl-format nil "~20:<~A~;~A~;~A~>" "foo" "bar" "baz") " foo bar baz" rlm@10: (cl-format nil "~20@<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz " rlm@10: (cl-format nil "~20@:<~A~;~A~;~A~>" "foo" "bar" "baz") " foo bar baz " rlm@10: (cl-format nil "~10,,2<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz" rlm@10: (cl-format nil "~10,10,2<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz" rlm@10: (cl-format nil "~10,10<~A~;~A~;~A~>" "foo" "bar" "baz") "foo barbaz" rlm@10: (cl-format nil "~20<~A~;~^~A~;~^~A~>" "foo" "bar" "baz") "foo bar baz" rlm@10: (cl-format nil "~20<~A~;~^~A~;~^~A~>" "foo" "bar") "foo bar" rlm@10: (cl-format nil "~20@<~A~;~^~A~;~^~A~>" "foo") "foo " rlm@10: (cl-format nil "~20:<~A~;~^~A~;~^~A~>" "foo") " foo" rlm@10: ) rlm@10: rlm@10: (simple-tests angle-bracket-max-column-tests rlm@10: (cl-format nil "~%;; ~{~<~%;; ~1,50:; ~A~>~}.~%" (into [] (.split "This function computes the circular thermodynamic coefficient of the thrombulator angle for use in determining the reaction distance" "\\s"))) rlm@10: "\n;; This function computes the circular\n;; thermodynamic coefficient of the thrombulator\n;; angle for use in determining the reaction\n;; distance.\n" rlm@10: (cl-format true "~%;; ~{~<~%;; ~:; ~A~>~}.~%" (into [] (.split "This function computes the circular thermodynamic coefficient of the thrombulator angle for use in determining the reaction distance." "\\s")))) rlm@10: rlm@10: (defn list-to-table [aseq column-width] rlm@10: (let [stream (get-pretty-writer (java.io.StringWriter.))] rlm@10: (binding [*out* stream] rlm@10: (doseq [row aseq] rlm@10: (doseq [col row] rlm@10: (cl-format true "~4D~7,vT" col column-width)) rlm@10: (prn))) rlm@10: (.flush stream) rlm@10: (.toString (:base @@(:base @@stream))))) rlm@10: rlm@10: (simple-tests column-writer-test rlm@10: (list-to-table (map #(vector % (* % %) (* % % %)) (range 1 21)) 8) rlm@10: " 1 1 1 \n 2 4 8 \n 3 9 27 \n 4 16 64 \n 5 25 125 \n 6 36 216 \n 7 49 343 \n 8 64 512 \n 9 81 729 \n 10 100 1000 \n 11 121 1331 \n 12 144 1728 \n 13 169 2197 \n 14 196 2744 \n 15 225 3375 \n 16 256 4096 \n 17 289 4913 \n 18 324 5832 \n 19 361 6859 \n 20 400 8000 \n") rlm@10: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; rlm@10: ;; The following tests are the various examples from the format rlm@10: ;; documentation in Common Lisp, the Language, 2nd edition, Chapter 22.3 rlm@10: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; rlm@10: rlm@10: (defn expt [base pow] (reduce * (repeat pow base))) rlm@10: rlm@10: (let [x 5, y "elephant", n 3] rlm@10: (simple-tests cltl-intro-tests rlm@10: (format nil "foo") "foo" rlm@10: (format nil "The answer is ~D." x) "The answer is 5." rlm@10: (format nil "The answer is ~3D." x) "The answer is 5." rlm@10: (format nil "The answer is ~3,'0D." x) "The answer is 005." rlm@10: (format nil "The answer is ~:D." (expt 47 x)) "The answer is 229,345,007." rlm@10: (format nil "Look at the ~A!" y) "Look at the elephant!" rlm@10: (format nil "Type ~:C to ~A." (char 4) "delete all your files") rlm@10: "Type Control-D to delete all your files." rlm@10: (format nil "~D item~:P found." n) "3 items found." rlm@10: (format nil "~R dog~:[s are~; is~] here." n (= n 1)) "three dogs are here." rlm@10: (format nil "~R dog~:*~[s are~; is~:;s are~] here." n) "three dogs are here." rlm@10: (format nil "Here ~[are~;is~:;are~] ~:*~R pupp~:@P." n) "Here are three puppies.")) rlm@10: rlm@10: (simple-tests cltl-B-tests rlm@10: ;; CLtL didn't have the colons here, but the spec requires them rlm@10: (format nil "~,,' ,4:B" 0xFACE) "1111 1010 1100 1110" rlm@10: (format nil "~,,' ,4:B" 0x1CE) "1 1100 1110" rlm@10: (format nil "~19,,' ,4:B" 0xFACE) "1111 1010 1100 1110" rlm@10: ;; This one was a nice idea, but nothing in the spec supports it working this way rlm@10: ;; (and SBCL doesn't work this way either) rlm@10: ;(format nil "~19,,' ,4:B" 0x1CE) "0000 0001 1100 1110") rlm@10: ) rlm@10: rlm@10: (simple-tests cltl-P-tests rlm@10: (format nil "~D tr~:@P/~D win~:P" 7 1) "7 tries/1 win" rlm@10: (format nil "~D tr~:@P/~D win~:P" 1 0) "1 try/0 wins" rlm@10: (format nil "~D tr~:@P/~D win~:P" 1 3) "1 try/3 wins") rlm@10: rlm@10: (defn foo [x] rlm@10: (format nil "~6,2F|~6,2,1,'*F|~6,2,,'?F|~6F|~,2F|~F" rlm@10: x x x x x x)) rlm@10: rlm@10: (simple-tests cltl-F-tests rlm@10: (foo 3.14159) " 3.14| 31.42| 3.14|3.1416|3.14|3.14159" rlm@10: (foo -3.14159) " -3.14|-31.42| -3.14|-3.142|-3.14|-3.14159" rlm@10: (foo 100.0) "100.00|******|100.00| 100.0|100.00|100.0" rlm@10: (foo 1234.0) "1234.00|******|??????|1234.0|1234.00|1234.0" rlm@10: (foo 0.006) " 0.01| 0.06| 0.01| 0.006|0.01|0.006") rlm@10: rlm@10: (defn foo-e [x] rlm@10: (format nil rlm@10: "~9,2,1,,'*E|~10,3,2,2,'?,,'$E|~9,3,2,-2,'%@E|~9,2E" rlm@10: x x x x)) rlm@10: rlm@10: ;; Clojure doesn't support float/double differences in representation rlm@10: (simple-tests cltl-E-tests rlm@10: (foo-e 0.0314159) " 3.14E-2| 31.42$-03|+.003E+01| 3.14E-2" ; Added this one rlm@10: (foo-e 3.14159) " 3.14E+0| 31.42$-01|+.003E+03| 3.14E+0" rlm@10: (foo-e -3.14159) " -3.14E+0|-31.42$-01|-.003E+03| -3.14E+0" rlm@10: (foo-e 1100.0) " 1.10E+3| 11.00$+02|+.001E+06| 1.10E+3" rlm@10: ; In Clojure, this is identical to the above rlm@10: ; (foo-e 1100.0L0) " 1.10L+3| 11.00$+02|+.001L+06| 1.10L+3" rlm@10: (foo-e 1.1E13) "*********| 11.00$+12|+.001E+16| 1.10E+13" rlm@10: (foo-e 1.1E120) "*********|??????????|%%%%%%%%%|1.10E+120" rlm@10: ; Clojure doesn't support real numbers this large rlm@10: ; (foo-e 1.1L1200) "*********|??????????|%%%%%%%%%|1.10L+1200" rlm@10: ) rlm@10: rlm@10: (simple-tests cltl-E-scale-tests rlm@10: (map rlm@10: (fn [k] (format nil "Scale factor ~2D~:*: |~13,6,2,VE|" rlm@10: (- k 5) 3.14159)) ;Prints 13 lines rlm@10: (range 13)) rlm@10: '("Scale factor -5: | 0.000003E+06|" rlm@10: "Scale factor -4: | 0.000031E+05|" rlm@10: "Scale factor -3: | 0.000314E+04|" rlm@10: "Scale factor -2: | 0.003142E+03|" rlm@10: "Scale factor -1: | 0.031416E+02|" rlm@10: "Scale factor 0: | 0.314159E+01|" rlm@10: "Scale factor 1: | 3.141590E+00|" rlm@10: "Scale factor 2: | 31.41590E-01|" rlm@10: "Scale factor 3: | 314.1590E-02|" rlm@10: "Scale factor 4: | 3141.590E-03|" rlm@10: "Scale factor 5: | 31415.90E-04|" rlm@10: "Scale factor 6: | 314159.0E-05|" rlm@10: "Scale factor 7: | 3141590.E-06|")) rlm@10: rlm@10: (defn foo-g [x] rlm@10: (format nil rlm@10: "~9,2,1,,'*G|~9,3,2,3,'?,,'$G|~9,3,2,0,'%G|~9,2G" rlm@10: x x x x)) rlm@10: rlm@10: ;; Clojure doesn't support float/double differences in representation rlm@10: (simple-tests cltl-G-tests rlm@10: (foo-g 0.0314159) " 3.14E-2|314.2$-04|0.314E-01| 3.14E-2" rlm@10: (foo-g 0.314159) " 0.31 |0.314 |0.314 | 0.31 " rlm@10: (foo-g 3.14159) " 3.1 | 3.14 | 3.14 | 3.1 " rlm@10: (foo-g 31.4159) " 31. | 31.4 | 31.4 | 31. " rlm@10: (foo-g 314.159) " 3.14E+2| 314. | 314. | 3.14E+2" rlm@10: (foo-g 3141.59) " 3.14E+3|314.2$+01|0.314E+04| 3.14E+3" rlm@10: ; In Clojure, this is identical to the above rlm@10: ; (foo-g 3141.59L0) " 3.14L+3|314.2$+01|0.314L+04| 3.14L+3" rlm@10: (foo-g 3.14E12) "*********|314.0$+10|0.314E+13| 3.14E+12" rlm@10: (foo-g 3.14E120) "*********|?????????|%%%%%%%%%|3.14E+120" rlm@10: ; Clojure doesn't support real numbers this large rlm@10: ; (foo-g 3.14L1200) "*********|?????????|%%%%%%%%%|3.14L+1200" rlm@10: ) rlm@10: rlm@10: (defn type-clash-error [fun nargs argnum right-type wrong-type] rlm@10: (format nil ;; CLtL has this format string slightly wrong rlm@10: "~&Function ~S requires its ~:[~:R ~;~*~]~ rlm@10: argument to be of type ~S,~%but it was called ~ rlm@10: with an argument of type ~S.~%" rlm@10: fun (= nargs 1) argnum right-type wrong-type)) rlm@10: rlm@10: (simple-tests cltl-Newline-tests rlm@10: (type-clash-error 'aref nil 2 'integer 'vector) rlm@10: "Function aref requires its second argument to be of type integer, rlm@10: but it was called with an argument of type vector.\n" rlm@10: (type-clash-error 'car 1 1 'list 'short-float) rlm@10: "Function car requires its argument to be of type list, rlm@10: but it was called with an argument of type short-float.\n") rlm@10: rlm@10: (simple-tests cltl-?-tests rlm@10: (format nil "~? ~D" "<~A ~D>" '("Foo" 5) 7) " 7" rlm@10: (format nil "~? ~D" "<~A ~D>" '("Foo" 5 14) 7) " 7" rlm@10: (format nil "~@? ~D" "<~A ~D>" "Foo" 5 7) " 7" rlm@10: (format nil "~@? ~D" "<~A ~D>" "Foo" 5 14 7) " 14") rlm@10: rlm@10: (defn f [n] (format nil "~@(~R~) error~:P detected." n)) rlm@10: rlm@10: (simple-tests cltl-paren-tests rlm@10: (format nil "~@R ~(~@R~)" 14 14) "XIV xiv" rlm@10: (f 0) "Zero errors detected." rlm@10: (f 1) "One error detected." rlm@10: (f 23) "Twenty-three errors detected.") rlm@10: rlm@10: (let [*print-level* nil *print-length* 5] rlm@10: (simple-tests cltl-bracket-tests rlm@10: (format nil "~@[ print level = ~D~]~@[ print length = ~D~]" rlm@10: *print-level* *print-length*) rlm@10: " print length = 5")) rlm@10: rlm@10: (let [foo "Items:~#[ none~; ~S~; ~S and ~S~ rlm@10: ~:;~@{~#[~; and~] ~ rlm@10: ~S~^,~}~]."] rlm@10: (simple-tests cltl-bracket1-tests rlm@10: (format nil foo) "Items: none." rlm@10: (format nil foo 'foo) "Items: foo." rlm@10: (format nil foo 'foo 'bar) "Items: foo and bar." rlm@10: (format nil foo 'foo 'bar 'baz) "Items: foo, bar, and baz." rlm@10: (format nil foo 'foo 'bar 'baz 'quux) "Items: foo, bar, baz, and quux.")) rlm@10: rlm@10: (simple-tests cltl-curly-bracket-tests rlm@10: (format nil rlm@10: "The winners are:~{ ~S~}." rlm@10: '(fred harry jill)) rlm@10: "The winners are: fred harry jill." rlm@10: rlm@10: (format nil "Pairs:~{ <~S,~S>~}." '(a 1 b 2 c 3)) rlm@10: "Pairs: ." rlm@10: rlm@10: (format nil "Pairs:~:{ <~S,~S>~}." '((a 1) (b 2) (c 3))) rlm@10: "Pairs: ." rlm@10: rlm@10: (format nil "Pairs:~@{ <~S,~S>~}." 'a 1 'b 2 'c 3) rlm@10: "Pairs: ." rlm@10: rlm@10: (format nil "Pairs:~:@{ <~S,~S>~}." '(a 1) '(b 2) '(c 3)) rlm@10: "Pairs: .") rlm@10: rlm@10: (simple-tests cltl-angle-bracket-tests rlm@10: (format nil "~10") "foo bar" rlm@10: (format nil "~10:") " foo bar" rlm@10: (format nil "~10:@") " foo bar " rlm@10: (format nil "~10") " foobar" rlm@10: (format nil "~10:") " foobar" rlm@10: (format nil "~10@") "foobar " rlm@10: (format nil "~10:@") " foobar ") rlm@10: rlm@10: (let [donestr "Done.~^ ~D warning~:P.~^ ~D error~:P." rlm@10: tellstr "~@{~@(~@[~R~^ ~]~A~)~}."] ;; The CLtL example is a little wrong here rlm@10: rlm@10: (simple-tests cltl-up-tests rlm@10: (format nil donestr) "Done." rlm@10: (format nil donestr 3) "Done. 3 warnings." rlm@10: (format nil donestr 1 5) "Done. 1 warning. 5 errors." rlm@10: (format nil tellstr 23) "Twenty-three." rlm@10: (format nil tellstr nil "losers") "Losers." rlm@10: (format nil tellstr 23 "losers") "Twenty-three losers." rlm@10: (format nil "~15<~S~;~^~S~;~^~S~>" 'foo) rlm@10: " foo" rlm@10: (format nil "~15<~S~;~^~S~;~^~S~>" 'foo 'bar) rlm@10: "foo bar" rlm@10: (format nil "~15<~S~;~^~S~;~^~S~>" 'foo 'bar 'baz) rlm@10: "foo bar baz")) rlm@10: rlm@10: (simple-tests cltl-up-x3j13-tests rlm@10: (format nil rlm@10: "~:{/~S~^ ...~}" rlm@10: '((hot dog) (hamburger) (ice cream) (french fries))) rlm@10: "/hot .../hamburger/ice .../french ..." rlm@10: (format nil rlm@10: "~:{/~S~:^ ...~}" rlm@10: '((hot dog) (hamburger) (ice cream) (french fries))) rlm@10: "/hot .../hamburger .../ice .../french" rlm@10: rlm@10: (format nil rlm@10: "~:{/~S~#:^ ...~}" ;; This is wrong in CLtL rlm@10: '((hot dog) (hamburger) (ice cream) (french fries))) rlm@10: "/hot .../hamburger") rlm@10: