N'th: Difference between revisions

1,045 bytes added ,  3 years ago
add Standard ML
(Updated to work with Nim 1.4: added missing parameter type. Some other changes.)
(add Standard ML)
Line 2,952:
ORA-01854: julian date must be between 1 and 5373484
</pre>
 
=={{header|Standard ML}}==
<lang sml>local
val v = Vector.tabulate (10, fn 1 => "st" | 2 => "nd" | 3 => "rd" | _ => "th")
fun getSuffix x =
if 3 < x andalso x < 21 then "th" else Vector.sub (v, x mod 10)
in
fun nth n =
Int.toString n ^ getSuffix (n mod 100)
end
 
(* some test ouput *)
val () = (print o concat o List.tabulate)
(26, fn i => String.concatWith "\t" (map nth [i, i + 250, i + 1000]) ^ "\n")</lang>
{{out}}
<pre>0th 250th 1000th
1st 251st 1001st
2nd 252nd 1002nd
3rd 253rd 1003rd
4th 254th 1004th
5th 255th 1005th
6th 256th 1006th
7th 257th 1007th
8th 258th 1008th
9th 259th 1009th
10th 260th 1010th
11th 261st 1011th
12th 262nd 1012th
13th 263rd 1013th
14th 264th 1014th
15th 265th 1015th
16th 266th 1016th
17th 267th 1017th
18th 268th 1018th
19th 269th 1019th
20th 270th 1020th
21st 271st 1021st
22nd 272nd 1022nd
23rd 273rd 1023rd
24th 274th 1024th
25th 275th 1025th</pre>
 
=={{header|Stata}}==
559

edits