Wiki

Ticket #254 (closed defect: wontfix)

Opened 14 years ago

Last modified 14 years ago

all expression on empty list returns true

Reported by: nevdelap Owned by: nevdelap
Priority: medium Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

class P
	def main is shared
		a = List<of int>()
		print all for b in a get b == 6

true

Is this a bug?

Currently it's like saying... "Are all the apples in the empty basket red?"

Neither Yes nor No is really correct. But...
The answer "No" makes sense because it can be qualified with "Because there are no apples."
The answer "Yes." can't be the right answer in any sense.

So I'm thinking all on an empty list should return false.

Attachments

all-empty-true.patch Download (2.4 KB) - added by hopscc 14 years ago.

Change History

Changed 14 years ago by nevdelap

  • priority changed from major to medium

Changed 14 years ago by hopscc

Changed 14 years ago by hopscc

  • owner set to Chuck
  • status changed from new to assigned

Sounds reasonable to me.
Heres a patch,relnote, modified tests.

Changed 14 years ago by Chuck

  • owner changed from Chuck to nevdelap

Python, Ruby and C# return true for "all" on empty lists.

$ python
>>> all([])
True

$ irb
>> [].all?
=> true

Also, they return "false" for "any" on an empty list.

C#:

/*
gmcs -debug+ -d:LINQ -r:System.Core list-all.cs
*/
using System;
using System.Collections.Generic;
using System.Linq;
class X {
	public static void Main() {
		var t = new List<int>();
		Console.WriteLine("{0}", t.All(x => true));
		Console.WriteLine("{0}", t.All(x => false));
		Console.WriteLine("{0}", t.Any(x => true));
		Console.WriteLine("{0}", t.Any(x => false));
		Console.WriteLine("done.");
	}
}
/* output:
True
True
False
False
done.
*/

Having "any" return false makes intuitive sense to me: "Do any shapes have an area greater than X? For an empty list, no because there aren't any shapes at all."

What about "all"? That's a little less intuitive. "Do all shapes have an area greater than X? For an empty list, ..." Well you might say no because there aren't even any shapes to pass such a test. But I think these languages say "yes" because there are no elements in the list that fail the test.

Pragmatically, have you been affected by this at all? If so, what about in the other languages?

Maybe we should also locate some discussion on this in those other communities.

Changed 14 years ago by nevdelap

  • status changed from assigned to closed
  • resolution set to wontfix

I found a thorough explanation in answer to this query...

 http://stackoverflow.com/questions/2195289/why-does-iqueryable-all-return-true-on-an-empty-collection

Although I'm going to have the read it again to fully get my head around it I'm happy that it's doing the correct thing and shouldn't be changed. I'll close the ticket.

Thanks Mike, Thanks Chuck.

Note: See TracTickets for help on using tickets.