ClojurePredicates函数

ClojurePredicates函数 首页 / Clojure入门教程 / ClojurePredicates函数

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)

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

链接:https://www.learnfk.comhttps://www.learnfk.com/clojure/clojure-predicates.html

来源:LearnFk无涯教程网

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。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

教程推荐

大模型微调实践课 -〔赵鹏昊/李杰〕

前端全链路优化实战课 -〔唐俊开〕

如何讲好一堂课 -〔薛雨〕

数据分析思维课 -〔郭炜〕

讲好故事 -〔涵柏〕

性能优化高手课 -〔尉刚强〕

容器实战高手课 -〔李程远〕

如何看懂一幅画 -〔罗桂霞〕

邱岳的产品实战 -〔邱岳〕

好记忆不如烂笔头。留下您的足迹吧 :)