Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should (every? string? []) yield true?

Tags:

clojure

Looking at the source code for every? makes clear why

(every? string? []) => true

This is because every? is implemented recursively and uses (nil? (seq coll)) to end recursion. But, my question is, what sense does this behaviour make? Just tripped over that.

I have solved my issue using

(and (seq x) (every? string? x))
like image 419
0dB Avatar asked Nov 08 '12 08:11

0dB


People also ask

Why do we need yield in Python?

yield keyword is used to create a generator function. A type of function that is memory efficient and can be used like an iterator object. In layman terms, the yield keyword will turn any expression that is given with it into a generator object and return it to the caller.

What is String intern () When and why should it be used?

String Interning is a method of storing only one copy of each distinct String Value, which must be immutable. By applying String. intern() on a couple of strings will ensure that all strings having the same contents share the same memory.

Which of the statement is true about String?

Expert-Verified AnswerA string does not let the user type letters numbers or words as it has already been written. Hence, it is the correct option.

What is the purpose of a yield statement?

The yield statement returns a generator object to the one who calls the function which contains yield, instead of simply returning a value.


1 Answers

Because it functions the same as the forall-quantifier. That is, it is initially assumed true and each application of the predicate is an attempt to prove it false. The existential quantifier (which is called some rather than any? in Clojure for inconsistencies sake) works the opposite way - it assumes false and each application of the predicate is an attempt to prove it true.

In other words, it's always true that something is true for all of none, and it's always false that something is true for some of none.

like image 173
Cubic Avatar answered Oct 12 '22 13:10

Cubic