我正在尝试从城市哈希图中获取某些值以在此处实现我的距离函数:
但是每次我说不支持的绑定形式:(latReturn record1)
这是我的latReturn和longReturn函数:
(defn latReturn [line]
(def x line)
(def y (string/split x #","))
(def my-map { :city (y 0)
:lat (y 1)
:long (y 2)
:country (y 3)
:iso2 (y 4)
:admin (y 5)
:capital (y 6)
:pop (y 7)
:popproper (y 8)
})
(read-string (my-map :lat))
)
(defn longReturn [line]
(def x line)
(def y (string/split x #","))
(def my-map { :city (y 0)
:lat (y 1)
:long (y 2)
:country (y 3)
:iso2 (y 4)
:admin (y 5)
:capital (y 6)
:pop (y 7)
:popproper (y 8)
})
(read-string (my-map :long))
)
我在这里做错了什么?
您的距离函数在对let
的呼叫中绑定错误。请阅读一些介绍Clojure的材料,以了解应如何使用let
。
基本上,看起来像这样:
(let [binding1 value1
binding2 value2]
(some-things-to-do-with binding1 binding2))
但是您可以将绑定中的内容作为绑定:
(let [...
(latReturn record1) (Math/toRadians ...)
...]
...)
您不能分配给(latReturn record1)
,因为这是一个函数调用。
[正如其他人已经指出的,请勿在def
或def
中使用defn
。这总是错误的(或者,直到您学习了足够的Clojure知道非常非常罕见的情况,也许是正确的,甚至通常不是这样),它总是错误的。