Clojure 學習入門(13)—— binding

來源:互聯網
上載者:User

 

 

 是串列的賦值的, 所以後面的binding可以用前面binding的值, 而 是不行的.

,,,,,,,,, and.要使用這些binding的函數會被這些binding的值影響的。比如給*out*一個新的binding會改變println函數的輸出終端。

, 和的用法:

; clojure connect to mysql; ithomer.net; 2013.12.10(ns myClojure.syntax.binding)(def ^:dynamic v 1) ; v is a global binding (defn f1 [] (println "f1: v =" v)) ; global binding of 1 (defn f2 [] (println "f2: before let v =" v) ; global binding (let [v 2] ; creates local binding v that shadows global one (println "f2: in let, v =" v) ; local binding of 2 (f1)) ; of 1 (println "f2: after let v =" v)) ; global binding of 1 (defn f3 [] (println "f3: before binding v =" v) ; global binding of 1 (binding [v 3] ; same global binding with new, temporary value (println "f3: in binding, v =" v) ; global binding of 3 (f1)) ; of 3 (println "f3: after binding v =" v)) ; global binding of 1 (defn f4 [] (def v 4) ; changes the value of the global binding (println "f4: after binding v =" v) ; of 4 (f1)) ; of 4 (f2)(f3)(f4)(println "after calling f4, v =" v) ; of 4

f2: before let v = 1f2: in let, v = 2f1: v = 1f2: after let v = 1f3: before binding v = 1f3: in binding, v = 3f1: v = 3f3: after binding v = 1f4: after binding v = 4f1: v = 4after calling f4, v = 4


Clojure入門教程

Clojure 基本文法


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.