From: "Martin J. Dürst" Date: 2013-08-03T17:00:39+09:00 Subject: [ruby-core:56348] Re: [CommonRuby - Feature #8723] Array.any? predicate returns true for empty array. On 2013/08/03 15:40, nurettin (Nurettin Onur TUGCU) wrote: > > Issue #8723 has been updated by nurettin (Nurettin Onur TUGCU). > > > I find I need to address all the questions > However I find the result needs not be defined. Also, defining "all?" or "any?" makes no sense for empty set since they will never execute. You say: > Also, defining "all?" or "any?" makes no sense for empty set since they will never execute. So should be write code like unless enum.empty? enum.all { |x| predicate(x) } end Think about this in a bigger context. Assume we are applying .any or .all not to a simple array, but to an array of arrays. We would e.g. write arrays.all { |a| a.all { |x| predicate(x) } } If we use what we currently have in Ruby, this just works, even if there are some empty lists in the 'arrays' array. With your proposal, we'd have to write a lot of special code. > ============ > > Of course I understand that there are other languages which do this the same, I also understand that it would break existing code, and I know that docs are clear, and of course I can write my own, but is it really correct behavior to treat undefinedness as truth? In my opinion, no. It would be incorrect behavior to treat undefinedness as truth, but the results of these operations are not undefined. They have a clear underlying mathematical background. People familiar with this area know what the results are, and they expect them to work the way they do. Anything else would be highly confusing for everybody except maybe beginners. I suggest you read some introductory book in this area (discrete math). An alternative is to read a book on Haskell, especially one that discusses code transformations/equivalences and proofs. Regards, Martin.