Seems related to:
Hi!
I noticed that the very useful ContainsAll function returns false when I check if a list contains an empty list.
This is demonstrable with simple formulas:
list('a', 'b', 'c').containsall(list('a', 'b')) returns true.
list('a', 'b', 'c').containsall(list('a')) returns true.
list('a', 'b', 'c').containsall(list()) returns false.
I feel like the last item should return true as well, since the empty set is a subset of any set.
I realize that this behavior is bypassable if I include a c…
I’m trying to check if two lists are identical.
E.g.
List(1,2).ContainsOnly(List(1,2))
returns true
List(1,2).ContainsOnly(List(1,2,3))
returns false
but now the weird one
List().ContainsOnly(List())
returns false , I expected true
The way around this is to use
List() = List()
returns true
and it works for the rest as expected
List(1,2) = List(1,2)
returns true
List(1,2) = List(1,2,3)
returns false
Community, have any thoughts on this? Does this seem expected to you? @jeo @Paul_Danyliuk @Federico.Stefanato @Johg_Ananda ?
I think the answer is in the description of what ContainsOnly()
does:
It’s searching for something … and you can’t search an empty list, so its false from the start. It doesn’t matter if you do:
List().ContainsOnly(List("foo"))
- this isn’t true because an empty list doesn’t have it
List().ContainsOnly(List())
- this isn’t true either because an empty list can’t have anything in it
Kind of like how zero can be true:
@Wallace_White you are getting unexpected behavior because Coda is answering a different question than you. You are asking is 0 true? but when you put a singular value into an if statement, Coda evaluates is value blank?
This feels more useful, after using Coda for several years, the ability to see if a value exists and to act accordingly … and I understand that other languages have their preferences. Good luck!
2 Likes
I see that perspective.
Another way to say this could be List()
clearly only contains nothing, and therefore any other list whose only contents are nothing must also only contain nothing.
1 Like
Interesting question, I had to research this.
It seems that mathematics agree with you, the empty set is a part of all sets…
In mathematics, the empty set is the unique set having no elements; its size or cardinality (count of elements in a set) is zero. Some axiomatic set theories ensure that the empty set exists by including an axiom of empty set, while in other theories, its existence can be deduced. Many possible properties of sets are vacuously true for the empty set.
In some textbooks and popularizations, the empty set is referred to as the "null set". However, null set is a distinct notion within the context o...
I agree with you that this is unexpected.
I would expect the following equivalency to always hold true:
ListA.ContainsOnly(ListB)
is just a shorthand for
ListB.FormulaMap(
ListA.Contains(CurrentValue)
).And()
and also this expression:
Sort(Unique(ListA)) = Sort(Unique(ListB))
And this holds in all cases except if both ListA and ListB are List()
, in which case all three expressions should return true, but only the latter two do. That strikes me as inconsistent.
1 Like