gpt4 book ai didi

clojure - 是否有用于序数指标的 Clojure 函数?

转载 作者:行者123 更新时间:2023-12-05 00:23:34 27 4
gpt4 key购买 nike

我想要一个函数来填充这张 map 的内容:

{: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 是否有 Clojure 函数indicators ?

(如果有更好的方法来描述这种功能 - 请告诉我)

最佳答案

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

关于clojure - 是否有用于序数指标的 Clojure 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28125706/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com