Redefining a let'd variable in Clojure loop

后端 未结 4 1329
难免孤独
难免孤独 2021-02-01 02:00

OK. I\'ve been tinkering with Clojure and I continually run into the same problem. Let\'s take this little fragment of code:

(let [x 128]
  (while (> x 1)
            


        
4条回答
  •  执笔经年
    2021-02-01 02:41

    You could more idiomatically use iterate and take-while instead,

    user> (->> 128
               (iterate #(/ % 2))
               (take-while (partial < 1)))
    
    (128 64 32 16 8 4 2)
    user>
    

提交回复
热议问题