我是 Clojure 的新手,所以最近几天我一直在阅读Clojure Koans 。在序列理解部分之前,事情进展得相当顺利。我在这部分苦苦挣扎。答案是可用的,但我不明白他们是如何得出这些答案的。在过去的两天里,我读了很多关于 Clojure 的文章,但它与 Ruby 有很大的不同,以至于我需要一段时间才能理解它。
该部分有五个“问题”,我无法弄清楚。以下是两个让我特别困惑的问题示例:
"And also filtering"
(= '(1 3 5 7 9)
(filter odd? (range 10))
(for [index __ :when (odd? index)]
index))
"And they trivially allow combinations of the two transformations"
(= '(1 9 25 49 81)
(map (fn [index] (* index index))
(filter odd? (range 10)))
(for [index (range 10) :when __]
__))
对于有使用 Clojure 经验的人,您能否解释一下他们是如何得出本节的解决方案的?不管我读了多少关于序列的内容,我都无法理解这一节。谢谢!