Enumerable#all? and empty arrays

(Andre Nathan) #1

Hello

I found this to be somewhat amusing:

a = []

=> []

a.all?

=> true

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

=> true

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

Best regards,
Andre

(Ara.T.Howard) #2

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

···

On Thu, 10 Aug 2006, Andre Nathan wrote:

Hello

I found this to be somewhat amusing:

a = []

=> []

a.all?

=> true

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

=> true

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

Best regards,
Andre

--
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama

(Carlos) #3

Andre Nathan wrote:

Hello

I found this to be somewhat amusing:

a = []

=> []

a.all?

=> 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.

···

--

(Florian Frank) #4

Andre Nathan wrote:

a = []
      

=> []
  

a.all?
      

=> true
  

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

=> 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.

···

--
Florian Frank

(Mauricio Fernandez) #5

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, Aug 10, 2006 at 01:41:48AM +0900, Andre Nathan wrote:

Hello

I found this to be somewhat amusing:

>> a = []
=> []
>> a.all?
=> true
>> a.all? { |i| i == 10 }
=> true

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

--
Mauricio Fernandez - http://eigenclass.org - singular Ruby

(Just Another Victim of the Ambient Morality) #6

"Andre Nathan" <andre@digirati.com.br> wrote in message
news:1155141696.24603.43.camel@andre.mz.digirati.com.br...

Hello

I found this to be somewhat amusing:

a = []

=> []

a.all?

=> true

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

=> true

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...

(Andre Nathan) #7

OK, thank you all for the explanations :slight_smile:

Andre

···

On Thu, 2006-08-10 at 03:03 +0900, Mauricio Fernandez 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.

(Juergen Strobel) #8

unless mathematician.is_an :intuitionist # (pretty rare)

Sorry I couldn't resist
-Jürgen

···

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

"Andre Nathan" <andre@digirati.com.br> wrote in message
news:1155141696.24603.43.camel@andre.mz.digirati.com.br...
> Hello
>
> I found this to be somewhat amusing:
>
>>> a = []
> => []
>>> a.all?
> => true
>>> a.all? { |i| i == 10 }
> => true
>
> 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...

--
The box said it requires Windows 95 or better so I installed Linux