Perl 6 also takes the position that all()
and any()
on empty lists should serve as sane base-cases for their respective reduction operators, and therefore all()
is true and any()
is false.
That is to say, all(a, b, c)
is equivalent to [&] a, b, c
, which is equivalent to a & b & c
(reduction on the "junctive and" operator, but you can ignore junctions and consider it a logical and for this post), and any(a, b, c)
is equivalent to [|] a, b, c
, which is equivalent to a | b | c
(reduction on the "junctive or" operator -- again, you can pretend it's the same as logical or without missing anything).
Any operator which can have reduction applied to it needs to have a defined behavior when reducing 0 terms, and usually this is done by having a natural identity element -- for instance, [+]()
(reduction of addition across zero terms) is 0 because 0 is the additive identity; adding zero to any expression leaves it unchanged. [*]()
is likewise 1 because 1 is the multiplicative identity. We've already said that all
is equivalent to [&]
and any
is equivalent to [|]
-- well, truth is the and-identity, and falsity is the or-identity -- x and True is x, and x or False is x. This makes it inevitable that all()
should be true and any()
should be false.
To put it in an entirely different (but practical) perspective, any
is a latch that starts off false and becomes true whenever it sees something true; all
is a latch that starts off true and becomes false whenever it sees something false. Giving them no arguments means giving them no chance to change state, so you're simply asking them what their "default" state is. :)