这用于创建参考值。创建参考值时,有一个提供验证器函数的选项,该函数将验证创建的值。

ref - 语法

(ref x options)

参数     -  " x"是需要提供给参考的值, "options"是可以提供的一组选项。

返回值 -  引用及其对应的值。

ref - 示例

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

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (def my-ref (ref 1 :validator pos?))
   (println @my-ref))
(Example)

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

1

参考链接

https://www.learnfk.com/clojure/clojure-ref.html