无涯教程-Clojure - send函数

38 阅读1分钟

此函数用于将值发送到代理。

send - 语法

(send agentname function value)

参数      -  " agentname"是将发送函数重定向到的代理, "function"用于确定更改代理价值的方式, "value"是传递给该函数的值,该值随后将用于相应地更新代理的值。

返回值  -  返回具有新值的代理对象 。

send - 示例

以下程序显示了有关如何使用它的示例。

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (def counter (agent 0))
   (println @counter)

(send counter + 100) (println "Incrementing Counter") (println @counter)) (Example)

上面的程序产生以下输出。

0
Incrementing Counter
0

参考链接

www.learnfk.com/clojure/clo…