在 Clojure 的同一个命名空间中使用函数之前,我是否需要声明它们?

Do I need to declare functions before they are used in the same namespace in Clojure?

我有这个代码片段:

(ns mylib-clojure.core)

(defn doWhatever2 [x]
  (doWhatever1 x))

(defn doWhatever1 [x]
  (inc x))

除非我将 doWhatever1 函数定义移动到 doWhatever2 之上,否则此代码不起作用。我必须这样做似乎很奇怪,因为我在同一个命名空间中。有没有一种方法可以在命名空间中声明我的函数而不必考虑顺序?

Clojure 编译器只执行一次,因此顺序很重要。

Clojure 确实提供了一种指定前向声明的方法:

(declare doWhatever1)

clojure.core/declare