Predicates是判断条件并提供true或false值的函数,所有这些函数都返回true或false值。
以下是Clojure中的Predicates示例。
(ns clojure.examples.example (:gen-class)) ;; This program displays Hello Learnfk (defn Example [] (def x (even? 0)) (println x) (def x (neg? 2)) (println x) (def x (odd? 3)) (println x) (def x (pos? 3)) (println x)) (Example)
上面的程序产生以下输出。
true false true true
除正常predicates函数外,Clojure还为谓predicates提供了更多函数。
Sr.No. | Methods & 描述 |
---|---|
1 |
every-pred 接受一组Predicates,并返回一个函数" f",如果所有组成Predicates针对所有参数返回逻辑真值,则返回true,否则返回false。 |
2 |
every? 如果Predicates对于每个值都为true,则返回true,否则为false。 |
3 |
some 返回值集合中x的任何predicates值的第一个逻辑真值。 |
4 |
not-any? 如果集合中值的任何predicates在逻辑上为true,则返回false,否则返回true。 链接:https://www.learnfk.comhttps://www.learnfk.com/clojure/clojure-predicates.html 来源:LearnFk无涯教程网 |
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)