什么`:-`在clojure的核心中意味着什么?

时间:2014-11-19 15:12:08

标签: types clojure

来自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}))))))

2 个答案:

答案 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