如何指定一个在 Clojure 中没有参数的函数?

Mo0*_*812 4 clojure

我想为我的一个小型项目编写一些规范,并且担心如何为不提供任何参数传递给它的函数编写规范。

我想为这个特定功能编写规范:

(defn get-total-pages []
  (int (Math/ceil (/ (count (get-posts)) posts-per-page))))
Run Code Online (Sandbox Code Playgroud)

它计算假设posts-per-page在一页上有帖子的总页数。该函数本身运行良好,但在向其添加以下规范时:

(s/fdef get-total-pages
  :args ()
  :ret int?)
Run Code Online (Sandbox Code Playgroud)

stest/check在没有警告的情况下,我无法对其执行任何操作:

:clojure.spec.test.check/ret {:result #error {
 :cause "Unable to construct gen at: [] for: clojure.spec.alpha$spec_impl$reify__2059@1232bda3"
...
Run Code Online (Sandbox Code Playgroud)

当不使用:args所有映射时,规范告诉我:args缺少,所以这里是我的最后一个问题:如何规范不提供参数的函数?

Tay*_*ood 8

:args无参数函数的列表可以指定为空s/cat规范:

(s/fdef get-total-pages
  :args (s/cat)
  :ret int?)
Run Code Online (Sandbox Code Playgroud)