1
我的問題是...什麼是更新currentRow nextRow bitPosition 的值每次(recur [currentRow nextRow bitPosition]))執行的好方法。現在我正在爲這樣一個事實而苦苦掙扎,即我不能在clojure中這樣做簡單的事情。相反,我被困在這個痛苦的世界裏,我甚至無法弄清楚如何在循環中設置一個變量爲一個新值。clojure循環變量賦值返回一個向量
//我希望我可以做到這一點
currentRow =(get myVector 0)
//這裏我的代碼
(loop [myVector []]
(let [
rule ruleParam
currentRow currentRowParam
nextRow 2r0
bitPosition 2r0
]
(when (bit-test rule (bit-and currentRow 2r111))
(
(bit-shift-right currentRow 1)
(bit-set nextRow 1)
(inc bitPosition)
))
(when (= false (bit-test rule (bit-and currentRow 2r111)))
(bit-shift-right currentRow 1)
(bit-set nextRow 1)
(inc bitPosition)
)
(recur [currentRow nextRow bitPosition]))
))
解決我的問題。感謝您的指導。
(defn firstFunc [[rule currentRowParam]]
(let [currentRowLocal (bit-shift-left currentRowParam 1) nextRowLocal 2r0 bitPositionLocal 0]
(loop [currentRow currentRowLocal nextRow nextRowLocal bitPosition bitPositionLocal]
(if (< bitPosition 31)
(if (bit-test rule (bit-and currentRow 2r111))
(recur
(bit-shift-right currentRow 1)
(bit-set nextRow bitPosition)
(inc bitPosition)
);end recur
(recur
(bit-shift-right currentRow 1)
nextRow
(inc bitPosition)
);end recur
)
;else
nextRow);end if (< bitPosition 31)
);end loop
);end let
);end defn firstFunc
(firstFunc2 [2r1110 2r11])
其中ruleParam和currentRowParam來自哪裏?在循環內的let內綁定它們很愚蠢,在循環運行時它們不能被改變 – noisesmith 2014-10-19 15:24:59
沒關係,我從你最後的再次調用中計算出來 – noisesmith 2014-10-19 15:29:01