【发布时间】:2021-05-21 01:03:58
【问题描述】:
所以我正在使用 Clojure 制作一个简单的程序,计算 BMI 并根据该计算返回该人是否健康。
这是我的代码
(defn bmi [weight height]
(def x (/ weight (Math/pow height 2)))
(println x)
(let [y x]
(cond
(< y 20.0) "Underweight"
(< y 25.0 and >= y 20.0) "Normal"
(< y 30.0 and >= y 25.0) "Obese"
(< y 40.0 and >= y 30.0) "Obese2"
:else "Obese3"))
)
(bmi 45.0 1.7)
我认为它是正确的,但是当我运行它时它告诉我错误。
CompilerException java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/and, compile:(/tmp/form-init8921870265637757493.clj:47:3)
谁能帮帮我?谢谢!
【问题讨论】:
-
请查看此文档来源列表,尤其是 Living Clojure 和 Clojure CheatSheet:github.com/io-tupelo/clj-template#documentation
标签: java functional-programming clojure