是否有用于序数指示符的 Clojure 函数?
Is there a Clojure function for ordinal indicators?
我想要一个函数来填充这张地图的内容:
{:1 "first" :2 "second" :3 "third" :4 "fourth" ... :100 "one-hundredth" ...}
所以我可以做类似于
的事情
(println "This is the " (:3 {... :3 "third" ...}) " item in the sequence")
> This is the third item in the sequence
是否有执行此操作的现有 Clojure 库?
我的问题是:是否有 ordinal indicators 的 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")
请注意 :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
我想要一个函数来填充这张地图的内容:
{:1 "first" :2 "second" :3 "third" :4 "fourth" ... :100 "one-hundredth" ...}
所以我可以做类似于
的事情(println "This is the " (:3 {... :3 "third" ...}) " item in the sequence")
> This is the third item in the sequence
是否有执行此操作的现有 Clojure 库?
我的问题是:是否有 ordinal indicators 的 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")
请注意 :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