本文介绍了问题与Clojure'contains'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用Closure Box来完成一些Clojure教程,并输入以下代码:

I am going through some Clojure tutorials using Closure Box, and entered the following code:

user> (def stooges (vector "Moe" "Larry" "Curly"))
#'user/stooges
user> (contains? stooges "Moe")
false

任何帮助是赞赏。

推荐答案

向量类似于数组。 返回 true 如果集合中存在。您应该查找键/索引0,1或2

A vector is similar to an array. contains? returns true if the key exists in the collection. You should be looking for the "key/index" 0, 1 or 2

user=> (def stooges (vector "Moe" "Larry" "Curly"))
#'user/stooges
user=> (contains? stooges 1)
true
user=> (contains? stooges 5)
false

如果使用散列...

user=> (def stooges {:moe "Moe" :larry "Larry" :curly "Curly"})
#'user/stooges
user=> (contains? stooges :moe)
true
user=> (contains? stooges :foo)
false

正如mikera所说,

As mikera suggests, you probably want something like clojure.core/some

这篇关于问题与Clojure'contains'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 15:56