ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### Validation函数 在继续介绍下一个引用类型之前,下面是一个validation函数的例子,他验证所有赋给Ref的值是数字。 ``` ; Note the use of the :validator directive when creating the Ref ; to assign a validation function which is integer? in this case. (def my-ref (ref 0 :validator integer?)) (try (dosync (ref-set my-ref 1) ; works ; The next line doesn't work, so the transaction is rolled back ; and the previous change isn't committed. (ref-set my-ref "foo")) (catch IllegalStateException e ; do nothing )) (println "my-ref =" @my-ref) ; due to validation failure -> 0 ```