【发布时间】:2018-08-24 19:22:38
【问题描述】:
我是 Lisp/Functional/Clojure 领域的新手,我有一个 JS 函数:
function buildString(someInteger) {
var question = "Initial text";
if (someInteger == 1) {
question += " put this string ";
} else if(someInteger == 2) {
question += " oh! another string ";
} else if(someInteger == 3) {
question += " guess what? ";
}
return question;
}
将其重写为 Clojure 函数的好方法是什么?我已经有一些使用“cond”Clojure 宏的代码,但我不确定不可变字符串“question”:
(defn build-string [some-integer]
(let [question "Initial text"]
(cond
(= some-integer 1) (str question "Add string one")
(= some-integer 2) (str question "Add string two")
(= some-integer 3) (str question "Add string three"))))
【问题讨论】:
-
请添加你已经尝试过的cljs代码。
标签: clojure clojurescript