Clojure - 斷言 some



返回集合中任何斷言值為 x 的第一個邏輯真值。

語法

以下是語法。

(some p1 col)

引數 - ‘p1’ 是需要測試的斷言。‘col’ 是需要測試的值的集合。

返回值 - 如果對每個值斷言都為真,則返回真,否則返回假。

示例

以下是 Clojure 中 some 的示例。

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (println (some even? '(1 2 3 4))))
(Example)

輸出

以上程式產生以下輸出。

true

請注意,在上述程式中,一旦斷言到達值為 2(偶數),函式將退出,並且不會測試 3 和 4 的值。

clojure_predicates.htm
廣告

© . All rights reserved.