通过参数获取 Clojure 向量
(def andre {:owner "Andre" :type "car" :cur-speed "100" :license-plate "ABC"})
(def blastoise {:owner "Blastoise" :type "truck" :cur-speed "120" :license-plate "XYZ"})
(def car-tax[andre blastoise])
(defn calculate-car-tax [v]
(for [v] (println (v)))
)
(calculate-car-tax(car-tax))
我收到这个异常: java.lang.IllegalArgumentException:for 在这一行中需要绑定向量 (cartax.cl:5) 中的偶数个形式
:(for [v] (println (v))) 这个 v 通过参数传递
(def andre {:owner "Andre" :type "car" :cur-speed "100" :license-plate "ABC"})
(def blastoise {:owner "Blastoise" :type "truck" :cur-speed "120" :license-plate "XYZ"})
(def car-tax[andre blastoise])
(defn calculate-car-tax [v]
(for [v] (println (v)))
)
(calculate-car-tax(car-tax))
I'm getting this exception:
java.lang.IllegalArgumentException: for requires an even number of forms in binding vector (cartax.cl:5)
in this line: (for [v] (println (v)))
this v is passed via parameter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要以下内容:
您需要将
for
宏与绑定一起使用。也就是说你想要一些东西在你的向量范围内。 “偶数”的原因是您可以一次覆盖多个向量!另外,参数最好不加括号;也就是说,请确保写下而不是
以下内容:
You likely want the following
You need to use the
for
macro with a binding. That is you want something to range over your vector. The reason for "even number" is that you can range over multiple vectors at once! Also arguments are best left unparenthesized; that is, make sure to writeand not
Here is a transcript: