它看起來像Clojure的let
是連續的,將對應於計劃let*
。 Clojure的是否有像計劃的let
的unsequential約束機制?Clojure的unsequential讓
3
A
回答
4
我相信binding
宏觀平行不連續的。
2
letfn是功能的並行結合的形式存在,讓人們編寫相互遞歸的本地功能。它並不像一般的,你尋求儘管它可以在緊要關頭使用。
user> (letfn [(a [] 4)
(b [] c)
(c [] a)]
(a))
4
結合可以使用,只要你,如果你嘗試使用並行綁定的動態作用域會給不是讓不同的結果*分配在瓦爾值的東西,要動態作用域
user> (def ^:dynamic x 4)
#'user/x
user> (defn foo [] x)
#'user/foo
user> (binding [x 8] (+ x (foo)))
16 ; the value of x that gets called by foo is modified by the caller
; yielding 16 instead of 12
user> (binding [x 8 a 7] (+ x (foo)))
; Evaluation aborted.
Unable to resolve var: a in this context
將在方案
user> (def ^:dynamic a 2)
#'user/a
user> (binding [x 8 a 7] (+ x a))
15
user> (binding [x 8 a (+ x 2)] (+ x a))
14 ; this would be 18 if the binding of x to 8 had been used
; instead the root value of 4 was used.
一般來說它是最常見的順序地結合或如果需要的話使用嵌套let
秒。
0
binding
不會給您與平行let
相同的功能,因爲它取決於綁定的存在。如前所述letfn
只要你不介意在功能包裝你的價值觀會工作。另一種解決方案是編寫一個並行使用宏讓:
(defmacro letp
[bindings & exprs]
(let [bindings (partition 2 bindings)
vars (->> bindings (map first) vec)
values (->> bindings (map second))]
`((fn ~vars [email protected])
[email protected])))
所以下面的成立:
(def a 7)
(letp [a 5 b a] b)
;;=> 7
相關問題
- 1. 迷茫「讓」 Clojure中
- 2. 讓Clojure運行(lein repl)
- 3. clojure函數,讓&返回值
- 4. 讓我們與Clojure的綁定
- 5. Clojure的讓VS多參數數量
- 6. 讓Clojure在後臺運行的JVM
- 7. Clojure的 - 在宏一個讓行不通
- 8. EVAL列表到一個讓上Clojure的
- 9. PHP array_column與unsequential指數返回錯誤的指數
- 10. 如何讓Clojure尊重`* assert *`變量?
- 11. 的Clojure -
- 12. 窩更好的辦法,如果,讓Clojure中
- 13. Clojure讓允許多個具有相同名稱的綁定
- 14. Android上的Clojure
- 15. CLR上的Clojure
- 16. 從Clojure的
- 17. Clojure中的caddr
- 18. 的Clojure:文檔
- 19. Clojure:讓示波器和函數返回值
- 20. Clojure部分應用 - 如何讓'地圖'返回一組函數?
- 21. 如何讓clojure webapp自動重新部署?
- 22. 如何讓clojure tools.analyzer忽略驗證步驟?
- 23. Clojure的Python的StringIO
- 24. Clojure中
- 25. Clojure中
- 26. Clojure sprintf?
- 27. Clojure中
- 28. Clojure中
- 29. Clojure stripMargin
- 30. Clojure中
更新了我的情況下,答案並不清楚我的意思 – Kevin 2012-08-07 20:09:42
我更新的格式更多使其更清晰。 – 2012-08-07 20:10:48
感謝(DEFN測試[] (結合[0 B(+ 1)] b))的 – locojay 2012-08-07 20:16:06