来自core.typed库的this code中:-
的含义是什么?
(t/ann play-many [(ta/Chan RPSResult) t/Int -> (t/Map t/Any t/Any)])
(defn play-many
"Play n matches from out-chan and report a summary of the results."
[out-chan n]
(t/loop [remaining :- t/Int, n ;; <======== This line
results :- (t/Map PlayerName t/Int), {}]
(if (zero? remaining)
results
(let [[m1 m2 winner] (a/<!! out-chan)]
(assert m1)
(assert m2)
(assert winner)
(recur (dec remaining)
(merge-with + results {winner 1}))))))
答案 0 :(得分:12)
如上所述,:-
只是一个关键字。但是,在您的上下文中,它是core.typed
注释的一部分,将循环绑定标记为特定类型:
(t/loop [remaining :- t/Int, n
results :- (t/Map PlayerName t/Int), {}]
...)
这意味着remaining
是一个整数,而results
是一个将玩家名称与整数相关联的地图。这些可以使用core.typed
类型检查程序进行验证。
答案 1 :(得分:6)
:-
是单个字符-
的关键字。
user=> :-
:-
user=> (class :-)
clojure.lang.Keyword