将布尔值映射到 clojure 中的列表
Mapping a boolean to a list in clojure
我正在尝试获取一个列表以根据特定数字评估 true/false。当我定义函数时,clojure 很好地定义了它。但它没有做我想做的事。刚刚学习 clojure...所以我还不太熟悉语法...如果这是一个新手问题,我们深表歉意。
理想情况下,它会接受像 (list 9 0 3) 这样的列表并将其评估为 (list true false true)
(defn myfunc [lst](map (> x 1) lst))
正确的语法如下:
(defn greater-than-one?
[x]
(< 1 x))
然后使用它:
(mapv greater-than-one? (list 9 0 3)) => [true false true]
在你原来的格式下,你也可以这样解决:
(defn myfunc [lst]
(map #(> % 1) lst))
并使用它:
(myfunc (list 9 0 3)) => (true false true)
您可能还会发现 this template project helpful in getting started. Please be sure to see the list of documentation。
我正在尝试获取一个列表以根据特定数字评估 true/false。当我定义函数时,clojure 很好地定义了它。但它没有做我想做的事。刚刚学习 clojure...所以我还不太熟悉语法...如果这是一个新手问题,我们深表歉意。
理想情况下,它会接受像 (list 9 0 3) 这样的列表并将其评估为 (list true false true)
(defn myfunc [lst](map (> x 1) lst))
正确的语法如下:
(defn greater-than-one?
[x]
(< 1 x))
然后使用它:
(mapv greater-than-one? (list 9 0 3)) => [true false true]
在你原来的格式下,你也可以这样解决:
(defn myfunc [lst]
(map #(> % 1) lst))
并使用它:
(myfunc (list 9 0 3)) => (true false true)
您可能还会发现 this template project helpful in getting started. Please be sure to see the list of documentation。