haw*_*eye 4 ordinals clojure ordinal ordinal-indicator
我想要一个将填充此地图内容的函数:
{:1 "first" :2 "second" :3 "third" :4 "fourth" ... :100 "one-hundredth" ...}
Run Code Online (Sandbox Code Playgroud)
所以我可以做类似的事情
(println "This is the " (:3 {... :3 "third" ...}) " item in the sequence")
> This is the third item in the sequence
Run Code Online (Sandbox Code Playgroud)
是否有现有的Clojure库可以做到这一点?
(如果有更好的方法来描述这种功能 - 请告诉我)
user=> (require '[clojure.pprint :as pprint])
nil
user=> (map #(pprint/cl-format nil "~:R" %) [1 2 3 4 100])
("first" "second" "third" "fourth" "one hundredth")
Run Code Online (Sandbox Code Playgroud)
请注意,这:1不是1,:也不是地图键的语法
user=> (pprint/pprint (into {} (map (fn [n] [n (pprint/cl-format nil "~:R" n)]) (range 20))))
{0 "zeroth",
7 "seventh",
1 "first",
4 "fourth",
15 "fifteenth",
13 "thirteenth",
6 "sixth",
17 "seventeenth",
3 "third",
12 "twelfth",
2 "second",
19 "nineteenth",
11 "eleventh",
9 "ninth",
5 "fifth",
14 "fourteenth",
16 "sixteenth",
10 "tenth",
18 "eighteenth",
8 "eighth"}
nil
Run Code Online (Sandbox Code Playgroud)