Subject: Re: FORMAT & abbreviated ordinals
From: (Rob Warnock)
Date: Fri, 02 Nov 2007 01:38:32 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Don Geddis  <> wrote:
| So if I do   (format t "~:R" 4)
| I get        fourth
| but I want   4th
| Any of you FORMAT wizards know a simple way to print abbreviated ordinals?

Not using "~R" per se, but I once had occasion to need the same
thing, and I did it something like this [though ISTR that I may
have used an AREF on a vector of 10 strings instead of the CASE]:

    > (defun ordinal-suffix (n)
	(let ((n (mod n 100)))
	  (if (<= 11 n 13)    ; special-case English-language rule
	    (let ((which (mod n 10)))
	      (case which
		((1) "st")
		((2) "nd")
		((3) "rd")
		(t "th"))))))

    > (loop for i to 225
	collect (format nil "~d~a" i (ordinal-suffix i)))

    ("0th" "1st" "2nd" "3rd" "4th" "5th" "6th" "7th" "8th" "9th"
     "10th" "11th" "12th" "13th" "14th" "15th" "16th" "17th" "18th"
     "19th" "20th" "21st" "22nd" "23rd" "24th" "25th" "26th" "27th"
     "28th" "29th" "30th" "31st" "32nd" "33rd" "34th" "35th" "36th"
     "37th" "38th" "39th" "40th" "41st" "42nd" "43rd" "44th" "45th"
     "46th" "47th" "48th" "49th" "50th" "51st" "52nd" "53rd" "54th"
     "55th" "56th" "57th" "58th" "59th" "60th" "61st" "62nd" "63rd"
     "64th" "65th" "66th" "67th" "68th" "69th" "70th" "71st" "72nd"
     "73rd" "74th" "75th" "76th" "77th" "78th" "79th" "80th" "81st"
     "82nd" "83rd" "84th" "85th" "86th" "87th" "88th" "89th" "90th"
     "91st" "92nd" "93rd" "94th" "95th" "96th" "97th" "98th" "99th"
     "100th" "101st" "102nd" "103rd" "104th" "105th" "106th" "107th"
     "108th" "109th" "110th" "111th" "112th" "113th" "114th" "115th"
     "116th" "117th" "118th" "119th" "120th" "121st" "122nd" "123rd"
     "124th" "125th" "126th" "127th" "128th" "129th" "130th" "131st"
     "132nd" "133rd" "134th" "135th" "136th" "137th" "138th" "139th"
     "140th" "141st" "142nd" "143rd" "144th" "145th" "146th" "147th"
     "148th" "149th" "150th" "151st" "152nd" "153rd" "154th" "155th"
     "156th" "157th" "158th" "159th" "160th" "161st" "162nd" "163rd"
     "164th" "165th" "166th" "167th" "168th" "169th" "170th" "171st"
     "172nd" "173rd" "174th" "175th" "176th" "177th" "178th" "179th"
     "180th" "181st" "182nd" "183rd" "184th" "185th" "186th" "187th"
     "188th" "189th" "190th" "191st" "192nd" "193rd" "194th" "195th"
     "196th" "197th" "198th" "199th" "200th" "201st" "202nd" "203rd"
     "204th" "205th" "206th" "207th" "208th" "209th" "210th" "211th"
     "212th" "213th" "214th" "215th" "216th" "217th" "218th" "219th"
     "220th" "221st" "222nd" "223rd" "224th" "225th")


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607