通勤还用于更改引用类型的值,就像alter和ref-set一样,唯一的区别是,这也需要放在" dosync"块中。
(commute refname fun)
参数 -'refname'是保存参考值的变量的名称。 "fun"是用于更改引用类型的值的函数。
返回值 - 引用及其相应的新值。
以下程序显示了有关如何使用它的示例。
(ns clojure.examples.example (:gen-class)) (defn Example [] (def counter (ref 0)) (defn change [counter] (dosync (commute counter inc))) (change counter) (println @counter) (change counter) (println @counter)) (Example)
上面的程序产生以下输出。
链接:https://www.learnfk.comhttps://www.learnfk.com/clojure/clojure-commute.html
来源:LearnFk无涯教程网
1 2
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕