Hello

I found this to be somewhat amusing:

a = []

=> []a.all?

=> truea.all? { |i| i == 10 }

=> true

Is there any reasoning for Enumerable#all? to always return true for

empty arrays?

Best regards,

Andre

Hello

I found this to be somewhat amusing:

a = []

=> []a.all?

=> truea.all? { |i| i == 10 }

=> true

Is there any reasoning for Enumerable#all? to always return true for

empty arrays?

Best regards,

Andre

On Thu, 10 Aug 2006, Andre N. wrote:

Is there any reasoning for Enumerable#all? to always return true for

empty arrays?Best regards,

Andre

well - it’s either that or false. we’d need maybe for it to really make

sense.

consider

[].all?{|x| x.nil?} # true or false??

either is arbitrary

-a

Andre N. wrote:

=> true

a.all? { |i| i == 10 }

=> true

Is there any reasoning for Enumerable#all? to always return true for

empty arrays?

It’s what modern logic says… or something like it.

Andre N. wrote:

=> true

Is there any reasoning for Enumerable#all? to always return true for

empty arrays?

I think they are modeled after universal and existential quantifiers in

predicate calculus:

a.all?(&b) is true iff for all x in a b[x].

This leads to a.all? being true.

a.any?(&b) is true iff there exists an x in a for which b[x].

This leads to a.any? being false.

On Thu, Aug 10, 2006 at 01:41:48AM +0900, Andre N. wrote:

Is there any reasoning for Enumerable#all? to always return true for

empty arrays?

a.all?{ … } == true

can be read as “All elements in a satisfy { … }”, which we can

interpret as

“there is no element in a such that { … } is not satisfied”, which is

obviously true if a is empty.

On Thu, 2006-08-10 at 03:03 +0900, Mauricio F. wrote:

can be read as “All elements in a satisfy { … }”, which we can interpret as

“there is no element in a such that { … } is not satisfied”, which is

obviously true if a is empty.

OK, thank you all for the explanations

Andre

On Thu, Aug 10, 2006 at 08:55:12AM +0900, Just Another Victim of the

Ambient M. wrote:

=> true

say the condition is true…

unless mathematician.is_an :intuitionist # (pretty rare)

Sorry I couldn’t resist

-JÃ¼rgen

“Andre N.” [email protected] wrote in message

news:[email protected]…

Is there any reasoning for Enumerable#all? to always return true for

empty arrays?

```
It's mathematically consistent.
You may be surprised to hear this but mathematicians are generally
```

optimists. Thus, if a condition is “vacuously satisfied,” then we

generally

say the condition is true…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs