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 ```